Search in sources :

Example 1 with NumericNode

use of com.fasterxml.jackson.databind.node.NumericNode in project swagger-core by swagger-api.

the class PropertyDeserializer method getEnum.

private static List<String> getEnum(JsonNode node, PropertyBuilder.PropertyId type) {
    final List<String> result = new ArrayList<String>();
    JsonNode detailNode = getDetailNode(node, type);
    if (detailNode != null) {
        ArrayNode an = (ArrayNode) detailNode;
        for (JsonNode child : an) {
            if (child instanceof TextNode || child instanceof NumericNode || child instanceof IntNode || child instanceof LongNode || child instanceof DoubleNode || child instanceof FloatNode) {
                result.add(child.asText());
            }
        }
    }
    return result.isEmpty() ? null : result;
}
Also used : IntNode(com.fasterxml.jackson.databind.node.IntNode) ArrayList(java.util.ArrayList) FloatNode(com.fasterxml.jackson.databind.node.FloatNode) DoubleNode(com.fasterxml.jackson.databind.node.DoubleNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) NumericNode(com.fasterxml.jackson.databind.node.NumericNode) LongNode(com.fasterxml.jackson.databind.node.LongNode)

Example 2 with NumericNode

use of com.fasterxml.jackson.databind.node.NumericNode in project lucene-solr by apache.

the class SmileWriterTest method getVal.

public static Object getVal(JsonNode value) {
    if (value instanceof NullNode) {
        return null;
    }
    if (value instanceof NumericNode) {
        return ((NumericNode) value).numberValue();
    }
    if (value instanceof BooleanNode) {
        ((BooleanNode) value).booleanValue();
    }
    if (value instanceof ObjectNode) {
        Iterator<Map.Entry<String, JsonNode>> it = ((ObjectNode) value).fields();
        Map result = new LinkedHashMap<>();
        while (it.hasNext()) {
            Map.Entry<String, JsonNode> e = it.next();
            result.put(e.getKey(), getVal(e.getValue()));
        }
        return result;
    }
    if (value instanceof ArrayNode) {
        ArrayList result = new ArrayList();
        Iterator<JsonNode> it = ((ArrayNode) value).elements();
        while (it.hasNext()) {
            result.add(getVal(it.next()));
        }
        return result;
    }
    if (value instanceof BinaryNode) {
        return ((BinaryNode) value).binaryValue();
    }
    return value.textValue();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) NumericNode(com.fasterxml.jackson.databind.node.NumericNode) BooleanNode(com.fasterxml.jackson.databind.node.BooleanNode) LinkedHashMap(java.util.LinkedHashMap) BinaryNode(com.fasterxml.jackson.databind.node.BinaryNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) NullNode(com.fasterxml.jackson.databind.node.NullNode)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 NumericNode (com.fasterxml.jackson.databind.node.NumericNode)2 ArrayList (java.util.ArrayList)2 BinaryNode (com.fasterxml.jackson.databind.node.BinaryNode)1 BooleanNode (com.fasterxml.jackson.databind.node.BooleanNode)1 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)1 FloatNode (com.fasterxml.jackson.databind.node.FloatNode)1 IntNode (com.fasterxml.jackson.databind.node.IntNode)1 LongNode (com.fasterxml.jackson.databind.node.LongNode)1 NullNode (com.fasterxml.jackson.databind.node.NullNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 TextNode (com.fasterxml.jackson.databind.node.TextNode)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1