Search in sources :

Example 1 with BooleanNode

use of com.fasterxml.jackson.databind.node.BooleanNode in project jsonschema2pojo by joelittlejohn.

the class RequiredRuleTest method applyAddsTextWhenRequired.

@Test
public void applyAddsTextWhenRequired() throws JClassAlreadyExistsException {
    JDefinedClass jclass = new JCodeModel()._class(TARGET_CLASS_NAME);
    ObjectMapper mapper = new ObjectMapper();
    BooleanNode descriptionNode = mapper.createObjectNode().booleanNode(true);
    JDocCommentable result = rule.apply("fooBar", descriptionNode, jclass, null);
    assertThat(result.javadoc(), sameInstance(jclass.javadoc()));
    assertThat(result.javadoc().size(), is(1));
    assertThat((String) result.javadoc().get(0), is("\n(Required)"));
}
Also used : JDocCommentable(com.sun.codemodel.JDocCommentable) JDefinedClass(com.sun.codemodel.JDefinedClass) JCodeModel(com.sun.codemodel.JCodeModel) BooleanNode(com.fasterxml.jackson.databind.node.BooleanNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with BooleanNode

use of com.fasterxml.jackson.databind.node.BooleanNode in project jsonschema2pojo by joelittlejohn.

the class RequiredRuleTest method applySkipsTextWhenNotRequired.

@Test
public void applySkipsTextWhenNotRequired() throws JClassAlreadyExistsException {
    JDefinedClass jclass = new JCodeModel()._class(TARGET_CLASS_NAME);
    ObjectMapper mapper = new ObjectMapper();
    BooleanNode descriptionNode = mapper.createObjectNode().booleanNode(false);
    JDocCommentable result = rule.apply("fooBar", descriptionNode, jclass, null);
    assertThat(result.javadoc(), sameInstance(jclass.javadoc()));
    assertThat(result.javadoc().size(), is(0));
}
Also used : JDocCommentable(com.sun.codemodel.JDocCommentable) JDefinedClass(com.sun.codemodel.JDefinedClass) JCodeModel(com.sun.codemodel.JCodeModel) BooleanNode(com.fasterxml.jackson.databind.node.BooleanNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with BooleanNode

use of com.fasterxml.jackson.databind.node.BooleanNode 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

BooleanNode (com.fasterxml.jackson.databind.node.BooleanNode)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 JCodeModel (com.sun.codemodel.JCodeModel)2 JDefinedClass (com.sun.codemodel.JDefinedClass)2 JDocCommentable (com.sun.codemodel.JDocCommentable)2 Test (org.junit.Test)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 BinaryNode (com.fasterxml.jackson.databind.node.BinaryNode)1 NullNode (com.fasterxml.jackson.databind.node.NullNode)1 NumericNode (com.fasterxml.jackson.databind.node.NumericNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1