boon
Simple opinionated Java for the novice to expert level Java Programmer. Low Ceremony. High Productivity.
Boon
I am trying to cook up a Groovy script to use with the Extended Choice Parameter plugin in Jenkins: https://wiki.jenkins-ci.org/display/JENKINS/Extended+Choice+Parameter+plugin.
From the plugin page: the groovy script should return a JSON object that corresponds to the "options" object referred to in https://github.com/jdorn/json-editor. The example script does not work and throws error.
Could someone tell me how I can have Boon.fromJSON() return a JSON editor object? My intention is to have a pre-defined set values beings shown as parameters, each accepting a text against it (i.e, render as textbox).
Example (following the JSON editor way):
{
"value1": "",
"value2": "",
"value3": ""
}
Even if it can be done without using Boon parser, it should be fine.
Source: (StackOverflow)
I am using Boon JSON and I'd like to change the name of a field on a class that is being generated from JSON.
I just want to change
{"first_name": "Cristine", "last_name": "McVie"}
So it maps to the Java fields:
String firstName;
String lastName;
I've already got everything working (ie, if I use camel-case in the JSON, the object is created properly.
I've tried the @JsonPropery
and (based on the suggestion in comments) the @Named
annotations on the class, like so:
public class Person {
@Named("first_name")
private String firstName;
@Named("first_name")
public String getFirstName() {
return firstName;
}
@Named("first_name")
public void setFirstName(String firstName) {
this.firstName = firstName;
}
Just for edification, this is why I didn't see @JsonProperty
working at first. This app is running in Eclipse debug mode, and I was trusting Eclipse to redeploy the updated code, but adding an annotation is apparently NOT enough to trigger the update. Had to restart the app to pick it up.
Source: (StackOverflow)
Using Boon Serialization (https://github.com/boonproject/boon) I am serializing JSON to an object of this type:
public class Car {
String make;
Map<String, Object> techSpecs;
}
The types of the values in techSpecs
are of type CharSequenceValue
and NumberValue
. This prevents my Car.equals()
logic from succeeding. If the values in the map were of type java.lang.*
then the equality checks would behave as expected.
How do I control this part of the serialization process? The ObjectMapperImpl
dependencies are:
JsonParserFactory jsonParserFactory = new JsonParserFactory()
.useFieldsFirst()
.lax() //allow loose parsing of JSON like JSON Smart
.setCharset(StandardCharsets.UTF_8) //Set the standard charset, defaults to UTF_8
.setLazyChop(true) //similar to chop but only does it after map.get
;
JsonSerializerFactory jsonSerializerFactory = new JsonSerializerFactory()
.useFieldsFirst() //one of these
//.addPropertySerializer( ) customize property output
//.addTypeSerializer( ) customize type output
.useJsonFormatForDates() //use json dates
//.addFilter( ) add a property filter to exclude properties
.includeEmpty().includeNulls().includeDefaultValues() //override defaults
.handleComplexBackReference() //uses identity map to track complex back reference and avoid them
.setHandleSimpleBackReference( true ) //looks for simple back reference for parent
.setCacheInstances( true ) //turns on caching for immutable objects
;
ObjectMapper engine = JsonFactory.create(jsonParserFactory, jsonSerializerFactory)
Source: (StackOverflow)