Example usage for com.fasterxml.jackson.databind.node JsonNodeType NUMBER

List of usage examples for com.fasterxml.jackson.databind.node JsonNodeType NUMBER

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node JsonNodeType NUMBER.

Prototype

JsonNodeType NUMBER

To view the source code for com.fasterxml.jackson.databind.node JsonNodeType NUMBER.

Click Source Link

Usage

From source file:com.spotify.hamcrest.jackson.IsJsonNumber.java

private IsJsonNumber(final Matcher<?> numberMatcher, final Function<NumericNode, Object> projection) {
    super(JsonNodeType.NUMBER);
    this.numberMatcher = Objects.requireNonNull(numberMatcher);
    this.projection = Objects.requireNonNull(projection);
}

From source file:io.macgyver.neorx.rest.NeoRxClientTest.java

@Test
public void testIntParam() {
    NeoRxClient c = new NeoRxClient();

    Assert.assertEquals(JsonNodeType.NUMBER,
            c.createParameters("abc", Integer.MAX_VALUE).get("abc").getNodeType());
}

From source file:io.macgyver.neorx.rest.NeoRxClientTest.java

@Test
public void testLongParam() {
    NeoRxClient c = new NeoRxClient();

    Assert.assertEquals(JsonNodeType.NUMBER,
            c.createParameters("abc", Long.MAX_VALUE).get("abc").getNodeType());

}

From source file:de.thingweb.typesystem.jsonschema.JsonSchemaType.java

public static JsonType getJsonType(JsonNode jsonSchemaNode) throws JsonSchemaException {
    JsonType jtype = null;// ww  w.j  a  v a  2  s  . com

    if (jsonSchemaNode != null) {
        JsonNode typeNode = jsonSchemaNode.findValue("type");
        if (typeNode != null) {
            switch (typeNode.asText()) {
            case "boolean":
                jtype = new JsonBoolean();
                break;
            case "integer":
            case "number":
                boolean exclusiveMinimum = false;
                JsonNode exclusiveMinimumNode = jsonSchemaNode.findValue("exclusiveMinimum");
                if (exclusiveMinimumNode != null
                        && exclusiveMinimumNode.getNodeType() == JsonNodeType.BOOLEAN) {
                    exclusiveMinimum = exclusiveMinimumNode.asBoolean();
                }
                boolean exclusiveMaximum = false;
                JsonNode exclusiveMaximumNode = jsonSchemaNode.findValue("exclusiveMaximum");
                if (exclusiveMaximumNode != null
                        && exclusiveMaximumNode.getNodeType() == JsonNodeType.BOOLEAN) {
                    exclusiveMaximum = exclusiveMaximumNode.asBoolean();
                }

                if ("integer".equals(typeNode.asText())) {
                    jtype = new JsonInteger();
                    JsonNode minimumNode = jsonSchemaNode.findValue("minimum");
                    if (minimumNode != null && minimumNode.getNodeType() == JsonNodeType.NUMBER) {
                        ((JsonInteger) jtype).setMinimum(minimumNode.asLong());
                    }
                    JsonNode maximumNode = jsonSchemaNode.findValue("maximum");
                    if (maximumNode != null && maximumNode.getNodeType() == JsonNodeType.NUMBER) {
                        ((JsonInteger) jtype).setMaximum(maximumNode.asLong());
                    }
                } else {
                    assert ("number".equals(typeNode.asText()));

                    jtype = new JsonNumber();
                    JsonNode minimumNode = jsonSchemaNode.findValue("minimum");
                    if (minimumNode != null && minimumNode.getNodeType() == JsonNodeType.NUMBER) {
                        ((JsonNumber) jtype).setMinimum(minimumNode.asDouble());
                    }
                    JsonNode maximumNode = jsonSchemaNode.findValue("maximum");
                    if (maximumNode != null && maximumNode.getNodeType() == JsonNodeType.NUMBER) {
                        ((JsonNumber) jtype).setMaximum(maximumNode.asDouble());
                    }
                }

                ((AbstractJsonNumeric) jtype).setExclusiveMinimum(exclusiveMinimum);
                ((AbstractJsonNumeric) jtype).setExclusiveMaximum(exclusiveMaximum);

                break;
            case "null":
                jtype = new JsonNull();
                break;
            case "string":
                jtype = new JsonString();
                break;
            case "array":
                JsonNode itemsNode = jsonSchemaNode.findValue("items");
                if (itemsNode != null && JsonNodeType.OBJECT == itemsNode.getNodeType()) {
                    jtype = new JsonArray(getJsonType(itemsNode));
                } else {
                    throw new JsonSchemaException("items not object");
                }

                break;
            case "object":
                JsonNode propertiesNode = jsonSchemaNode.findValue("properties");
                if (propertiesNode != null && JsonNodeType.OBJECT == propertiesNode.getNodeType()) {
                    Iterator<Entry<String, JsonNode>> iter = propertiesNode.fields();
                    Map<String, JsonType> properties = new HashMap<String, JsonType>();
                    while (iter.hasNext()) {
                        Entry<String, JsonNode> e = iter.next();
                        JsonNode nodeProp = e.getValue();
                        properties.put(e.getKey(), getJsonType(nodeProp));
                    }
                    jtype = new JsonObject(properties);
                } else {
                    throw new JsonSchemaException("Properties not object");
                }
                // required
                JsonNode requiredNode = jsonSchemaNode.findValue("required");
                if (requiredNode != null && JsonNodeType.ARRAY == requiredNode.getNodeType()) {
                    ArrayNode an = (ArrayNode) requiredNode;
                    Iterator<JsonNode> iterReq = an.elements();
                    while (iterReq.hasNext()) {
                        JsonNode nreq = iterReq.next();
                        if (JsonNodeType.STRING == nreq.getNodeType()) {
                            ((JsonObject) jtype).addRequired(nreq.asText());
                        } else {
                            throw new JsonSchemaException("Unexpected required node: " + nreq);
                        }
                    }
                }
                break;
            }
        }
    }

    return jtype;
}

From source file:io.swagger.parser.util.SwaggerDeserializer.java

public Object extension(JsonNode jsonNode) {
    if (jsonNode.getNodeType().equals(JsonNodeType.BOOLEAN)) {
        return jsonNode.asBoolean();
    }//from w  w  w . ja  v a2 s. co m
    if (jsonNode.getNodeType().equals(JsonNodeType.STRING)) {
        return jsonNode.asText();
    }
    if (jsonNode.getNodeType().equals(JsonNodeType.NUMBER)) {
        NumericNode n = (NumericNode) jsonNode;
        if (n.isLong()) {
            return jsonNode.asLong();
        }
        if (n.isInt()) {
            return jsonNode.asInt();
        }
        if (n.isBigDecimal()) {
            return jsonNode.textValue();
        }
        if (n.isBoolean()) {
            return jsonNode.asBoolean();
        }
        if (n.isFloat()) {
            return jsonNode.floatValue();
        }
        if (n.isDouble()) {
            return jsonNode.doubleValue();
        }
        if (n.isShort()) {
            return jsonNode.intValue();
        }
        return jsonNode.asText();
    }
    if (jsonNode.getNodeType().equals(JsonNodeType.ARRAY)) {
        ArrayNode an = (ArrayNode) jsonNode;
        List<Object> o = new ArrayList<Object>();
        for (JsonNode i : an) {
            Object obj = extension(i);
            if (obj != null) {
                o.add(obj);
            }
        }
        return o;
    }
    return jsonNode;
}

From source file:io.swagger.parser.util.SwaggerDeserializer.java

public Double getDouble(String key, ObjectNode node, boolean required, String location, ParseResult result) {
    Double value = null;/*from  w ww .  ja v a 2  s .co  m*/
    JsonNode v = node.get(key);
    if (node == null || v == null) {
        if (required) {
            result.missing(location, key);
            result.invalid();
        }
    } else if (v.getNodeType().equals(JsonNodeType.NUMBER)) {
        value = v.asDouble();
    }
    return value;
}

From source file:io.swagger.parser.util.SwaggerDeserializer.java

public Number getNumber(String key, ObjectNode node, boolean required, String location, ParseResult result) {
    Number value = null;//from   www .j a  v a 2 s.c om
    JsonNode v = node.get(key);
    if (node == null || v == null) {
        if (required) {
            result.missing(location, key);
            result.invalid();
        }
    } else if (v.getNodeType().equals(JsonNodeType.NUMBER)) {
        value = v.numberValue();
    }
    return value;
}

From source file:io.swagger.v3.parser.util.OpenAPIDeserializer.java

public BigDecimal getBigDecimal(String key, ObjectNode node, boolean required, String location,
        ParseResult result) {/*from   ww w .jav a2s. c  o m*/
    BigDecimal value = null;
    JsonNode v = node.get(key);
    if (node == null || v == null) {
        if (required) {
            result.missing(location, key);
            result.invalid();
        }
    } else if (v.getNodeType().equals(JsonNodeType.NUMBER)) {
        value = new BigDecimal(v.asText());
    } else if (!v.isValueNode()) {
        result.invalidType(location, key, "double", node);
    }
    return value;
}

From source file:io.swagger.parser.util.SwaggerDeserializer.java

public Integer getInteger(String key, ObjectNode node, boolean required, String location, ParseResult result) {
    Integer value = null;//from   ww  w.  j a  va  2s .c om
    JsonNode v = node.get(key);
    if (node == null || v == null) {
        if (required) {
            result.missing(location, key);
            result.invalid();
        }
    } else if (v.getNodeType().equals(JsonNodeType.NUMBER)) {
        value = v.intValue();
    }
    return value;
}

From source file:io.swagger.v3.parser.util.OpenAPIDeserializer.java

public Integer getInteger(String key, ObjectNode node, boolean required, String location, ParseResult result) {
    Integer value = null;/*from w  w w  .  ja v a  2s.  c  o  m*/
    JsonNode v = node.get(key);
    if (node == null || v == null) {
        if (required) {
            result.missing(location, key);
            result.invalid();
        }
    } else if (v.getNodeType().equals(JsonNodeType.NUMBER)) {
        if (v.isInt()) {
            value = v.intValue();
        }
    } else if (!v.isValueNode()) {
        result.invalidType(location, key, "integer", node);
    }
    return value;
}