Search in sources :

Example 1 with POJONode

use of com.fasterxml.jackson.databind.node.POJONode in project navajo by Dexels.

the class APIValue method setValueOnNodeForType.

// private static final String TYPE_BOOLEAN = "boolean";
public static void setValueOnNodeForType(ObjectNode node, String id, String type, Property property, ArticleRuntime runtime) throws APIException {
    if (property == null || property.getTypedValue() == null) {
        node.putNull(id);
    } else {
        if (TYPE_SELECTION.equals(type)) {
            ArrayNode options = runtime.getObjectMapper().createArrayNode();
            if (property.getAllSelections() != null && property.getAllSelections().size() > 0) {
                for (Selection s : property.getAllSelections()) {
                    ObjectNode option = runtime.getObjectMapper().createObjectNode();
                    option.put("selected", s.isSelected());
                    option.put("value", s.getValue());
                    option.put("name", s.getName());
                    options.add(option);
                }
            }
            node.set(id, options);
        } else if (TYPE_DATETIME.equals(type)) {
            validatedType(property, Property.DATE_PROPERTY, id);
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
            String ISO8601Date = df.format(((Date) property.getTypedValue()));
            node.put(id, ISO8601Date);
        } else if (TYPE_INTEGER.equals(type)) {
            // Null number are sometimes represented as empty strings.
            if (property.getTypedValue() instanceof String && ((String) property.getTypedValue()).trim().length() == 0) {
                node.putNull(id);
            } else {
                Integer value = -1;
                try {
                    value = Integer.parseInt(property.getValue());
                } catch (NumberFormatException e) {
                    throw new APIException("Id " + id + " says it is an integer but cannot be parsed to an int", null, APIErrorCode.InternalError);
                }
                node.put(id, value);
            }
        } else {
            if (property.getType().equals(Property.SELECTION_PROPERTY)) {
                if (property.getSelected() == null || property.getSelected().getName() == Selection.DUMMY_SELECTION) {
                    node.putNull(id);
                } else {
                    node.put(id, property.getSelected().getName());
                }
            } else if (property.getType().equals(Property.BINARY_PROPERTY)) {
                // Put the binary object in - TmlBinarySerializer will take care of serializing it
                node.set(id, new POJONode(property.getTypedValue()));
            } else {
                // Default
                node.put(id, property.getValue());
            }
        }
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Selection(com.dexels.navajo.document.Selection) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) POJONode(com.fasterxml.jackson.databind.node.POJONode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with POJONode

use of com.fasterxml.jackson.databind.node.POJONode in project jackson-databind by FasterXML.

the class TestTreeTraversingParser method testBinaryPojo.

public void testBinaryPojo() throws Exception {
    byte[] inputBinary = new byte[] { 1, 2, 100 };
    POJONode n = new POJONode(inputBinary);
    JsonParser p = n.traverse();
    assertNull(p.getCurrentToken());
    assertToken(JsonToken.VALUE_EMBEDDED_OBJECT, p.nextToken());
    byte[] data = p.getBinaryValue();
    assertNotNull(data);
    assertArrayEquals(inputBinary, data);
    Object pojo = p.getEmbeddedObject();
    assertSame(data, pojo);
    p.close();
}
Also used : POJONode(com.fasterxml.jackson.databind.node.POJONode)

Aggregations

POJONode (com.fasterxml.jackson.databind.node.POJONode)2 Selection (com.dexels.navajo.document.Selection)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1