Example usage for com.fasterxml.jackson.databind.node ObjectNode getClass

List of usage examples for com.fasterxml.jackson.databind.node ObjectNode getClass

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:io.swagger.test.processors.JacksonProcessorTest.java

@Test
public void testConvertYamlContent() throws Exception {
    String input = "name: fehguy\nuserId: 42";
    EntityProcessorFactory.addProcessor(JacksonProcessor.class, JacksonProcessor.APPLICATION_YAML_TYPE);

    InputStream is = new ByteArrayInputStream(input.getBytes());
    MediaType t = MediaType.valueOf("application/yaml");

    ObjectNode o = (ObjectNode) EntityProcessorFactory.readValue(t, is, JsonNode.class);
    assertEquals(o.getClass(), ObjectNode.class);
    assertEquals(o.get("name").asText(), "fehguy");
    assertEquals(o.get("userId").asText(), "42");
}

From source file:io.swagger.test.processors.JacksonProcessorTest.java

@Test
public void testConvertXMLContent() throws Exception {
    String input = "<user><id>1</id><name>fehguy</name></user>";

    EntityProcessorFactory.addProcessor(JacksonProcessor.class, MediaType.APPLICATION_XML_TYPE);

    InputStream is = new ByteArrayInputStream(input.getBytes());
    ObjectNode o = (ObjectNode) EntityProcessorFactory.readValue(MediaType.APPLICATION_XML_TYPE, is,
            JsonNode.class);
    assertEquals(o.getClass(), ObjectNode.class);
    assertEquals(o.get("name").asText(), "fehguy");
}

From source file:io.swagger.test.processors.JacksonProcessorTest.java

@Test
public void testConvertJsonContent() throws Exception {
    String input = "{\"name\":\"fehguy\"}";
    EntityProcessorFactory.addProcessor(JacksonProcessor.class, MediaType.APPLICATION_JSON_TYPE);

    InputStream is = new ByteArrayInputStream(input.getBytes());
    ObjectNode o = (ObjectNode) EntityProcessorFactory.readValue(MediaType.APPLICATION_JSON_TYPE, is,
            JsonNode.class);
    assertEquals(o.getClass(), ObjectNode.class);
    assertEquals(o.get("name").asText(), "fehguy");
}

From source file:org.apache.streams.twitter.processor.TwitterEventProcessor.java

@Override
public List<StreamsDatum> process(StreamsDatum entry) {

    // first check for valid json
    ObjectNode node = (ObjectNode) entry.getDocument();

    LOGGER.debug("{} processing {}", STREAMS_ID, node.getClass());

    String json = null;/*from   www.  ja va 2 s .co m*/
    try {
        json = mapper.writeValueAsString(node);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    }

    if (StringUtils.isNotEmpty(json)) {

        // since data is coming from outside provider, we don't know what type the events are
        Class inClass = TwitterEventClassifier.detectClass(json);

        // if the target is string, just pass-through
        if (java.lang.String.class.equals(outClass))
            return Lists.newArrayList(new StreamsDatum(json));
        else {
            // convert to desired format
            Object out = null;
            try {
                out = convert(node, inClass, outClass);
            } catch (ActivitySerializerException e) {
                LOGGER.warn("Failed deserializing", e);
                return Lists.newArrayList();
            } catch (JsonProcessingException e) {
                LOGGER.warn("Failed parsing JSON", e);
                return Lists.newArrayList();
            }

            if (out != null && validate(out, outClass))
                return Lists.newArrayList(new StreamsDatum(out));
        }
    }

    return Lists.newArrayList();

}