Example usage for com.fasterxml.jackson.databind.node JsonNodeFactory instance

List of usage examples for com.fasterxml.jackson.databind.node JsonNodeFactory instance

Introduction

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

Prototype

JsonNodeFactory instance

To view the source code for com.fasterxml.jackson.databind.node JsonNodeFactory instance.

Click Source Link

Usage

From source file:test.TestFinal.java

public static void main(String[] args) {
    //??//from   w  w w . ja  v a2s.c  o m

    //      ObjectNode datanode = JsonNodeFactory.instance.objectNode();
    //      datanode.put(Constant.JSON_VERIFYCODES, "00c49b0ba48843e9946a3f9636406950");
    //      createNewIMUserSingle(datanode);
    // LOGIN  regist1
    ObjectNode datanode = JsonNodeFactory.instance.objectNode();
    datanode.put(Constant.JSON_PASSWORD, "liufacai1");
    datanode.put(Constant.JSON_TELEPHONE, "9999");

    ObjectNode createNewIMUserSingleNode = createNewIMUserSingle(datanode);
    // regist2
    //      ObjectNode datanode = JsonNodeFactory.instance.objectNode();
    //      datanode.put(Constant.JSON_ID, "ff8080814dd21098014dd213e3d20001");
    //      datanode.put(Constant.JSON_NAME, "3test");
    //      datanode.put(Constant.JSON_COMPANY_NAME, "3?");
    //      datanode.put(Constant.JSON_COMPANY_ISSAMEPEOPLE, "0");
    //      datanode.put(Constant.JSON_COMPANY_BUSINESSLICENSE, "??xcv".getBytes());
    //      datanode.put(Constant.JSON_COMPANY_IDCARD, "test".getBytes());
    //      datanode.put(Constant.JSON_COMPANY_POSITIONPROVE, "".getBytes());
    //      createNewIMUserSingle(datanode);
}

From source file:com.datis.kafka.stream.PageViewUntypedDemo.java

public static void main(String[] args) throws Exception {
    Properties props = new Properties();
    props.put(StreamsConfig.APPLICATION_ID_CONFIG, "streams-pageview-untyped");
    props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
    props.put(StreamsConfig.ZOOKEEPER_CONNECT_CONFIG, "localhost:2181");
    props.put(StreamsConfig.TIMESTAMP_EXTRACTOR_CLASS_CONFIG, JsonTimestampExtractor.class);

    // setting offset reset to earliest so that we can re-run the demo code with the same pre-loaded data
    props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");

    KStreamBuilder builder = new KStreamBuilder();

    final Serializer<JsonNode> jsonSerializer = new JsonSerializer();
    final Deserializer<JsonNode> jsonDeserializer = new JsonDeserializer();
    final Serde<JsonNode> jsonSerde = Serdes.serdeFrom(jsonSerializer, jsonDeserializer);

    KStream<String, JsonNode> views = builder.stream(Serdes.String(), jsonSerde, "streams-pageview-input");

    KTable<String, JsonNode> users = builder.table(Serdes.String(), jsonSerde, "streams-userprofile-input");

    KTable<String, String> userRegions = users.mapValues(new ValueMapper<JsonNode, String>() {
        @Override//from  ww w  .  j  a v a2s. c  om
        public String apply(JsonNode record) {
            return record.get("region").textValue();
        }
    });

    KStream<JsonNode, JsonNode> regionCount = views
            .leftJoin(userRegions, new ValueJoiner<JsonNode, String, JsonNode>() {
                @Override
                public JsonNode apply(JsonNode view, String region) {
                    ObjectNode jNode = JsonNodeFactory.instance.objectNode();

                    return jNode.put("user", view.get("user").textValue())
                            .put("page", view.get("page").textValue())
                            .put("region", region == null ? "UNKNOWN" : region);
                }
            }).map(new KeyValueMapper<String, JsonNode, KeyValue<String, JsonNode>>() {
                @Override
                public KeyValue<String, JsonNode> apply(String user, JsonNode viewRegion) {
                    return new KeyValue<>(viewRegion.get("region").textValue(), viewRegion);
                }
            })
            .countByKey(TimeWindows.of("GeoPageViewsWindow", 7 * 24 * 60 * 60 * 1000L).advanceBy(1000),
                    Serdes.String())
            // TODO: we can merge ths toStream().map(...) with a single toStream(...)
            .toStream().map(new KeyValueMapper<Windowed<String>, Long, KeyValue<JsonNode, JsonNode>>() {
                @Override
                public KeyValue<JsonNode, JsonNode> apply(Windowed<String> key, Long value) {
                    ObjectNode keyNode = JsonNodeFactory.instance.objectNode();
                    keyNode.put("window-start", key.window().start()).put("region", key.key());

                    ObjectNode valueNode = JsonNodeFactory.instance.objectNode();
                    valueNode.put("count", value);

                    return new KeyValue<>((JsonNode) keyNode, (JsonNode) valueNode);
                }
            });

    // write to the result topic
    regionCount.to(jsonSerde, jsonSerde, "streams-pageviewstats-untyped-output");

    KafkaStreams streams = new KafkaStreams(builder, props);
    streams.start();

    // usually the stream application would be running forever,
    // in this example we just let it run for some time and stop since the input data is finite.
    Thread.sleep(5000L);

    streams.close();
}

From source file:com.jeeffy.test.streams.pageview.PageViewUntypedDemo.java

public static void main(String[] args) throws Exception {
    Properties props = new Properties();
    props.put(StreamsConfig.APPLICATION_ID_CONFIG, "streams-pageview-untyped");
    props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
    props.put(StreamsConfig.ZOOKEEPER_CONNECT_CONFIG, "localhost:2181");
    props.put(StreamsConfig.TIMESTAMP_EXTRACTOR_CLASS_CONFIG, JsonTimestampExtractor.class);

    // setting offset reset to earliest so that we can re-run the demo code with the same pre-loaded data
    props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");

    KStreamBuilder builder = new KStreamBuilder();

    final Serializer<JsonNode> jsonSerializer = new JsonSerializer();
    final Deserializer<JsonNode> jsonDeserializer = new JsonDeserializer();
    final Serde<JsonNode> jsonSerde = Serdes.serdeFrom(jsonSerializer, jsonDeserializer);

    KStream<String, JsonNode> views = builder.stream(Serdes.String(), jsonSerde, "streams-pageview-input");

    KTable<String, JsonNode> users = builder.table(Serdes.String(), jsonSerde, "streams-userprofile-input",
            "streams-userprofile-store-name");

    KTable<String, String> userRegions = users.mapValues(new ValueMapper<JsonNode, String>() {
        @Override// w  w w  . j  a v a  2s . c  o  m
        public String apply(JsonNode record) {
            return record.get("region").textValue();
        }
    });

    KStream<JsonNode, JsonNode> regionCount = views
            .leftJoin(userRegions, new ValueJoiner<JsonNode, String, JsonNode>() {
                @Override
                public JsonNode apply(JsonNode view, String region) {
                    ObjectNode jNode = JsonNodeFactory.instance.objectNode();

                    return jNode.put("user", view.get("user").textValue())
                            .put("page", view.get("page").textValue())
                            .put("region", region == null ? "UNKNOWN" : region);
                }
            }).map(new KeyValueMapper<String, JsonNode, KeyValue<String, JsonNode>>() {
                @Override
                public KeyValue<String, JsonNode> apply(String user, JsonNode viewRegion) {
                    return new KeyValue<>(viewRegion.get("region").textValue(), viewRegion);
                }
            }).groupByKey(Serdes.String(), jsonSerde)
            .count(TimeWindows.of(7 * 24 * 60 * 60 * 1000L).advanceBy(1000),
                    "RollingSevenDaysOfPageViewsByRegion")
            // TODO: we can merge ths toStream().map(...) with a single toStream(...)
            .toStream().map(new KeyValueMapper<Windowed<String>, Long, KeyValue<JsonNode, JsonNode>>() {
                @Override
                public KeyValue<JsonNode, JsonNode> apply(Windowed<String> key, Long value) {
                    ObjectNode keyNode = JsonNodeFactory.instance.objectNode();
                    keyNode.put("window-start", key.window().start()).put("region", key.key());

                    ObjectNode valueNode = JsonNodeFactory.instance.objectNode();
                    valueNode.put("count", value);

                    return new KeyValue<>((JsonNode) keyNode, (JsonNode) valueNode);
                }
            });

    // write to the result topic
    regionCount.to(jsonSerde, jsonSerde, "streams-pageviewstats-untyped-output");

    KafkaStreams streams = new KafkaStreams(builder, props);
    streams.start();

    // usually the stream application would be running forever,
    // in this example we just let it run for some time and stop since the input data is finite.
    Thread.sleep(5000L);

    streams.close();
}

From source file:de.thingweb.mockup.MockupLauncher.java

public static void main(String[] args) throws Exception {

    // Note: One can also set specific ports
    // e.g., ServientBuilder.getCoapBinding().setPort(5699);
    // ServientBuilder.getHttpBinding().setPort(8081);

    Thing mockup = new Thing("Room_Automation");

    mockup.addProperty(new Property.Builder("Room_temperature")
            .setValueType(JsonNodeFactory.instance.textNode("{ \"type\": \"number\" }")).setWriteable(true)
            .build());/*  w  w w  .j a va  2  s  .co  m*/

    MockupLauncher launcher = new MockupLauncher(mockup);

    ThingInterface thingIfc = launcher.start();

    thingIfc.setProperty("Room_temperature", 22.3);

}

From source file:io.liveoak.filesystem.HTTPFilesystemResourceTest.java

@BeforeClass
public static void setup() throws Exception {
    loadExtension("fs", new FilesystemExtension());
    installTestAppResource("fs", "files", JsonNodeFactory.instance.objectNode());
}

From source file:net.hamnaberg.json.Template.java

public static Template create(Iterable<Property> data) {
    ObjectNode obj = JsonNodeFactory.instance.objectNode();
    if (!Iterables.isEmpty(data)) {
        obj.set("data", Property.toArrayNode(data));
    }//from w  w  w . j a v a 2  s  . c  o m
    return new Template(obj);
}

From source file:io.fabric8.collector.elasticsearch.JsonNodes.java

/**
 * Sets a property on a node/* w  w w  .ja  v a2 s  .  com*/
 */
public static boolean set(JsonNode node, String name, String text) {
    JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
    return set(node, name, nodeFactory.textNode(text));
}

From source file:io.liveoak.filesystem.aggregating.HTTPAggregatingFilesystemResourceTest.java

@BeforeClass
public static void loadExtensions() throws Exception {
    loadExtension("aggr-fs", new AggregatingFilesystemExtension());
    installTestAppResource("aggr-fs", "aggr", JsonNodeFactory.instance.objectNode());
}

From source file:edumsg.core.CommandsHelp.java

public static void handleError(String app, String method, String errorMsg, String correlationID,
        Logger logger) {/*ww  w .  j  a v a2s.  c o  m*/
    JsonNodeFactory nf = JsonNodeFactory.instance;
    MyObjectMapper mapper = new MyObjectMapper();
    ObjectNode node = nf.objectNode();
    node.put("app", app);
    node.put("method", method);
    node.put("status", "Bad Request");
    node.put("code", "400");
    node.put("message", errorMsg);
    try {
        submit(app, mapper.writeValueAsString(node), correlationID, logger);
    } catch (JsonGenerationException e) {
        //logger.log(Level.SEVERE, e.getMessage(), e);
    } catch (JsonMappingException e) {
        //logger.log(Level.SEVERE, e.getMessage(), e);
    } catch (IOException e) {
        //logger.log(Level.SEVERE, e.getMessage(), e);
    }
}

From source file:com.flipkart.zjsonpatch.TestDataGenerator.java

public static JsonNode generate(int count) {
    ArrayNode jsonNode = JsonNodeFactory.instance.arrayNode();
    for (int i = 0; i < count; i++) {
        ObjectNode objectNode = JsonNodeFactory.instance.objectNode();
        objectNode.put("name", name.get(random.nextInt(name.size())));
        objectNode.put("age", age.get(random.nextInt(age.size())));
        objectNode.put("gender", gender.get(random.nextInt(gender.size())));
        ArrayNode countryNode = getArrayNode(country.subList(random.nextInt(country.size() / 2),
                (country.size() / 2) + random.nextInt(country.size() / 2)));
        objectNode.put("country", countryNode);
        ArrayNode friendNode = getArrayNode(friends.subList(random.nextInt(friends.size() / 2),
                (friends.size() / 2) + random.nextInt(friends.size() / 2)));
        objectNode.put("friends", friendNode);
        jsonNode.add(objectNode);//from   w  w  w .j a v  a 2s .c  o m
    }
    return jsonNode;
}