use of com.fasterxml.jackson.databind.node.ArrayNode in project jvm-serializers by eishay.
the class JacksonJsonTree method readMedia.
protected static Media readMedia(JsonNode node) {
Media media = new Media();
JsonNode bitrate = node.get("bitrate");
if (bitrate != null && !bitrate.isNull()) {
media.bitrate = bitrate.intValue();
media.hasBitrate = true;
}
media.copyright = node.path("copyright").textValue();
media.duration = node.path("duration").longValue();
media.format = node.path("format").textValue();
media.height = node.path("height").intValue();
media.player = Media.Player.valueOf(node.get("player").textValue());
ArrayNode personsArrayNode = (ArrayNode) node.get("persons");
int size = personsArrayNode.size();
List<String> persons = new ArrayList<String>(size);
for (JsonNode person : personsArrayNode) {
persons.add(person.textValue());
}
media.persons = persons;
media.size = node.get("size").intValue();
media.title = node.get("title").textValue();
media.uri = node.get("uri").textValue();
media.width = node.get("width").intValue();
return media;
}
use of com.fasterxml.jackson.databind.node.ArrayNode in project jvm-serializers by eishay.
the class JacksonJsonTree method addMedia.
protected static ObjectNode addMedia(Media media, ObjectNode node) {
if (media.hasBitrate) {
node.put("bitrate", media.bitrate);
}
node.put("copyright", media.copyright);
node.put("duration", media.duration);
node.put("format", media.format);
node.put("height", media.height);
ArrayNode persons = node.arrayNode();
for (String person : media.persons) {
persons.add(person);
}
node.set("persons", persons);
node.put("player", media.player.name());
node.put("size", media.size);
node.put("title", media.title);
node.put("uri", media.uri);
node.put("width", media.width);
return node;
}
use of com.fasterxml.jackson.databind.node.ArrayNode in project jvm-serializers by eishay.
the class JacksonJsonTree method readMediaContent.
protected static MediaContent readMediaContent(JsonNode root) throws IOException {
MediaContent mediaContent = new MediaContent();
mediaContent.media = readMedia(root.get("media"));
mediaContent.images = readImages((ArrayNode) root.get("images"));
return mediaContent;
}
use of com.fasterxml.jackson.databind.node.ArrayNode in project jsonschema2pojo by joelittlejohn.
the class DefaultRule method getDefaultSet.
/**
* Creates a default value for a set property by:
* <ol>
* <li>Creating a new {@link LinkedHashSet} with the correct generic type
* <li>Using {@link Arrays#asList(Object...)} to initialize the set with the
* correct default values
* </ol>
*
* @param fieldType
* the java type that applies for this field ({@link Set} with
* some generic type argument)
* @param node
* the node containing default values for this set
* @return an expression that creates a default value that can be assigned
* to this field
*/
private JExpression getDefaultSet(JType fieldType, JsonNode node) {
JClass setGenericType = ((JClass) fieldType).getTypeParameters().get(0);
JClass setImplClass = fieldType.owner().ref(LinkedHashSet.class);
setImplClass = setImplClass.narrow(setGenericType);
JInvocation newSetImpl = JExpr._new(setImplClass);
if (node instanceof ArrayNode && node.size() > 0) {
JInvocation invokeAsList = fieldType.owner().ref(Arrays.class).staticInvoke("asList");
for (JsonNode defaultValue : node) {
invokeAsList.arg(getDefaultValue(setGenericType, defaultValue));
}
newSetImpl.arg(invokeAsList);
} else if (!ruleFactory.getGenerationConfig().isInitializeCollections()) {
return JExpr._null();
}
return newSetImpl;
}
use of com.fasterxml.jackson.databind.node.ArrayNode in project jsonschema2pojo by joelittlejohn.
the class DefaultRule method getDefaultList.
/**
* Creates a default value for a list property by:
* <ol>
* <li>Creating a new {@link ArrayList} with the correct generic type
* <li>Using {@link Arrays#asList(Object...)} to initialize the list with
* the correct default values
* </ol>
*
* @param fieldType
* the java type that applies for this field ({@link List} with
* some generic type argument)
* @param node
* the node containing default values for this list
* @return an expression that creates a default value that can be assigned
* to this field
*/
private JExpression getDefaultList(JType fieldType, JsonNode node) {
JClass listGenericType = ((JClass) fieldType).getTypeParameters().get(0);
JClass listImplClass = fieldType.owner().ref(ArrayList.class);
listImplClass = listImplClass.narrow(listGenericType);
JInvocation newListImpl = JExpr._new(listImplClass);
if (node instanceof ArrayNode && node.size() > 0) {
JInvocation invokeAsList = fieldType.owner().ref(Arrays.class).staticInvoke("asList");
for (JsonNode defaultValue : node) {
invokeAsList.arg(getDefaultValue(listGenericType, defaultValue));
}
newListImpl.arg(invokeAsList);
} else if (!ruleFactory.getGenerationConfig().isInitializeCollections()) {
return JExpr._null();
}
return newListImpl;
}
Aggregations