Search in sources :

Example 16 with TextNode

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

the class DescriptionRuleTest method applyAddsDescriptionToJavadoc.

@Test
public void applyAddsDescriptionToJavadoc() throws JClassAlreadyExistsException {
    JDefinedClass jclass = new JCodeModel()._class(TARGET_CLASS_NAME);
    ObjectMapper mapper = new ObjectMapper();
    TextNode descriptionNode = mapper.createObjectNode().textNode("some description");
    JDocComment result = rule.apply("fooBar", descriptionNode, jclass, null);
    assertThat(result, sameInstance(jclass.javadoc()));
    assertThat(result.size(), is(1));
    assertThat((String) result.get(0), is("some description"));
}
Also used : JDefinedClass(com.sun.codemodel.JDefinedClass) TextNode(com.fasterxml.jackson.databind.node.TextNode) JCodeModel(com.sun.codemodel.JCodeModel) JDocComment(com.sun.codemodel.JDocComment) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 17 with TextNode

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

the class TypeRuleTest method applyGeneratesDate.

@Test
public void applyGeneratesDate() {
    JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put("type", "string");
    TextNode formatNode = TextNode.valueOf("date-time");
    objectNode.set("format", formatNode);
    JType mockDateType = mock(JType.class);
    FormatRule mockFormatRule = mock(FormatRule.class);
    when(mockFormatRule.apply(eq("fooBar"), eq(formatNode), Mockito.isA(JType.class), isNull(Schema.class))).thenReturn(mockDateType);
    when(ruleFactory.getFormatRule()).thenReturn(mockFormatRule);
    JType result = rule.apply("fooBar", objectNode, jpackage, null);
    assertThat(result, equalTo(mockDateType));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Schema(org.jsonschema2pojo.Schema) JPackage(com.sun.codemodel.JPackage) TextNode(com.fasterxml.jackson.databind.node.TextNode) JCodeModel(com.sun.codemodel.JCodeModel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JType(com.sun.codemodel.JType) Test(org.junit.Test)

Example 18 with TextNode

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

the class TestTreeTraversingParser method testTextAsBinary.

public void testTextAsBinary() throws Exception {
    TextNode n = new TextNode("   APs=\n");
    JsonParser p = n.traverse();
    assertNull(p.getCurrentToken());
    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    byte[] data = p.getBinaryValue();
    assertNotNull(data);
    assertArrayEquals(new byte[] { 0, -5 }, data);
    assertNull(p.nextToken());
    p.close();
    assertTrue(p.isClosed());
    // Also: let's verify we get an exception for garbage...
    n = new TextNode("?!??");
    p = n.traverse();
    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    try {
        p.getBinaryValue();
    } catch (InvalidFormatException e) {
        verifyException(e, "Illegal character");
    }
    p.close();
}
Also used : TextNode(com.fasterxml.jackson.databind.node.TextNode) InvalidFormatException(com.fasterxml.jackson.databind.exc.InvalidFormatException)

Example 19 with TextNode

use of com.fasterxml.jackson.databind.node.TextNode in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class InfoArchiveRestClient method getValidJsonRequestForExport.

private String getValidJsonRequestForExport(String exportConfigurationUri, List<SearchResult> searchResults) {
    JsonNodeFactory jsonNodeFactory = new ObjectMapper().getNodeFactory();
    ObjectNode root = jsonNodeFactory.objectNode();
    ArrayNode includedRows = jsonNodeFactory.arrayNode();
    for (SearchResult searchResult : searchResults) {
        for (Row row : searchResult.getRows()) {
            includedRows.add(row.getId());
        }
    }
    TextNode exportConfiguration = jsonNodeFactory.textNode(exportConfigurationUri);
    root.set("exportConfiguration", exportConfiguration);
    root.set("includedRows", includedRows);
    return root.toString();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Example 20 with TextNode

use of com.fasterxml.jackson.databind.node.TextNode in project XRTB by benmfaul.

the class Impression method doNative.

/**
	 * Handle the native impression
	 */
void doNative() {
    JsonNode node = rnode.get("native");
    if (node != null) {
        JsonNode child = null;
        nativead = true;
        nativePart = new NativePart();
        child = node.path("layout");
        if (child != null) {
            nativePart.layout = child.intValue();
        }
        if (node.path("assets") instanceof MissingNode == false) {
            ArrayNode array = (ArrayNode) node.path("assets");
            for (JsonNode x : array) {
                child = x.path("title");
                if (child instanceof MissingNode == false) {
                    nativePart.title = new Title();
                    nativePart.title.len = child.path("len").intValue();
                    if (x.path("required") instanceof MissingNode == false) {
                        nativePart.title.required = x.path("required").intValue();
                    }
                }
                child = x.path("img");
                if (child instanceof MissingNode == false) {
                    nativePart.img = new Img();
                    nativePart.img.w = child.path("w").intValue();
                    nativePart.img.h = child.path("h").intValue();
                    if (x.path("required") instanceof MissingNode == false) {
                        nativePart.img.required = x.path("required").intValue();
                    }
                    if (child.path("mimes") instanceof MissingNode == false) {
                        if (child.path("mimes") instanceof TextNode) {
                            nativePart.img.mimes.add(child.get("mimes").asText());
                        } else {
                            array = (ArrayNode) child.path("mimes");
                            for (JsonNode nx : array) {
                                nativePart.img.mimes.add(nx.textValue());
                            }
                        }
                    }
                }
                child = x.path("video");
                if (child instanceof MissingNode == false) {
                    nativePart.video = new NativeVideo();
                    nativePart.video.linearity = child.path("linearity").intValue();
                    nativePart.video.minduration = child.path("minduration").intValue();
                    nativePart.video.maxduration = child.path("maxduration").intValue();
                    if (x.path("required") instanceof MissingNode == false) {
                        nativePart.video.required = x.path("required").intValue();
                    }
                    if (child.path("mimes") instanceof MissingNode == false) {
                        array = (ArrayNode) child.path("protocols");
                        for (JsonNode nx : array) {
                            nativePart.video.protocols.add(nx.textValue());
                        }
                    }
                }
                child = x.path("data");
                if (child instanceof MissingNode == false) {
                    Data data = new Data();
                    if (x.path("required") instanceof MissingNode == false) {
                        data.required = x.path("required").intValue();
                    }
                    if (child.path("len") instanceof MissingNode == false) {
                        data.len = child.path("len").intValue();
                    }
                    data.type = child.path("type").intValue();
                    nativePart.data.add(data);
                }
            }
        }
    }
}
Also used : NativeVideo(com.xrtb.nativeads.creative.NativeVideo) Img(com.xrtb.nativeads.creative.Img) Title(com.xrtb.nativeads.creative.Title) JsonNode(com.fasterxml.jackson.databind.JsonNode) MissingNode(com.fasterxml.jackson.databind.node.MissingNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) Data(com.xrtb.nativeads.creative.Data) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

TextNode (com.fasterxml.jackson.databind.node.TextNode)23 Test (org.junit.Test)8 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)7 IntNode (com.fasterxml.jackson.databind.node.IntNode)7 ArrayList (java.util.ArrayList)7 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)6 JCodeModel (com.sun.codemodel.JCodeModel)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 MissingNode (com.fasterxml.jackson.databind.node.MissingNode)4 JType (com.sun.codemodel.JType)4 List (java.util.List)4 TreeNode (com.fasterxml.jackson.core.TreeNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 JDefinedClass (com.sun.codemodel.JDefinedClass)2 JDocComment (com.sun.codemodel.JDocComment)2 NavMap (com.xrtb.blocks.NavMap)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2