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:com.googlecode.jsonschema2pojo.SchemaMapperTest.java

@Test
public void generateCreatesSchemaFromExampleJsonWhenInJsonMode() throws IOException {

    URL schemaContent = this.getClass().getResource("/schema/address.json");

    ObjectNode schemaNode = JsonNodeFactory.instance.objectNode();

    final SchemaRule mockSchemaRule = mock(SchemaRule.class);

    final GenerationConfig mockGenerationConfig = mock(GenerationConfig.class);
    when(mockGenerationConfig.getSourceType()).thenReturn(SourceType.JSON);

    final SchemaGenerator mockSchemaGenerator = mock(SchemaGenerator.class);
    when(mockSchemaGenerator.schemaFromExample(schemaContent)).thenReturn(schemaNode);

    final RuleFactory mockRuleFactory = mock(RuleFactory.class);
    when(mockRuleFactory.getSchemaRule()).thenReturn(mockSchemaRule);
    when(mockRuleFactory.getGenerationConfig()).thenReturn(mockGenerationConfig);

    new SchemaMapper(mockRuleFactory, mockSchemaGenerator).generate(new JCodeModel(), "Address",
            "com.example.package", schemaContent);

    ArgumentCaptor<JPackage> capturePackage = ArgumentCaptor.forClass(JPackage.class);

    verify(mockSchemaRule).apply(eq("Address"), eq(schemaNode), capturePackage.capture(),
            Mockito.isA(Schema.class));

    assertThat(capturePackage.getValue().name(), is("com.example.package"));

}

From source file:io.gs2.auth.Gs2AuthClient.java

/**
 * ??????<br>/*from   w w w  .  java2s .co m*/
 * <br>
 *
 * @param request 
        
 * @return ?
        
 */

public CreateOnceOnetimeTokenResult createOnceOnetimeToken(CreateOnceOnetimeTokenRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode().put("scriptName", request.getScriptName());
    if (request.getGrant() != null)
        body.put("grant", request.getGrant());
    if (request.getArgs() != null)
        body.put("args", request.getArgs());

    HttpPost post = createHttpPost(Gs2Constant.ENDPOINT_HOST + "/onetime/once/token", credential, ENDPOINT,
            CreateOnceOnetimeTokenRequest.Constant.MODULE, CreateOnceOnetimeTokenRequest.Constant.FUNCTION,
            body.toString());
    if (request.getRequestId() != null) {
        post.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    return doRequest(post, CreateOnceOnetimeTokenResult.class);

}

From source file:io.confluent.connect.elasticsearch.internals.Response.java

private ObjectNode parseError(String error) {
    if (error != null && !error.trim().isEmpty()) {
        try {//from   w w  w. j  av  a  2  s.c  om
            return (ObjectNode) new ObjectMapper().readTree(error);
        } catch (IOException e) {
            log.error("Exception when parsing to JSON:", e);
        }
    }
    return JsonNodeFactory.instance.objectNode();
}

From source file:com.yahoo.elide.parsers.state.RecordTerminalState.java

@Override
public Supplier<Pair<Integer, JsonNode>> handlePatch(StateContext state) {
    final JsonNode empty = JsonNodeFactory.instance.nullNode();
    JsonApiDocument jsonApiDocument = state.getJsonApiDocument();

    Data<Resource> data = jsonApiDocument.getData();

    if (data == null) {
        throw new InvalidEntityBodyException("Expected data but found null");
    }/* w  w w .  ja  v  a  2 s . c om*/

    if (data.get() instanceof SingleElementSet) {
        Resource resource = data.get().iterator().next();
        if (record.matchesId(resource.getId())) {
            patch(data.get().iterator().next(), state.getRequestScope());
            return () -> Pair.of(HttpStatus.SC_NO_CONTENT, empty);
        }
    }
    throw new InvalidEntityBodyException("Expected single element but found list");
}

From source file:org.fusesource.restygwt.examples.server.GreetingServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    System.out.println("Creating custom greeting.");
    try {//from  w  w w. j  a v a 2s.  co m
        ObjectMapper mapper = new ObjectMapper();
        ObjectNode nameObject = mapper.readValue(req.getInputStream(), ObjectNode.class);
        String name = nameObject.get("name").asText();

        String greeting = "Hello " + name;
        ObjectNode resultObject = new ObjectNode(JsonNodeFactory.instance);
        resultObject.put("greeting", greeting);
        mapper.writeValue(resp.getOutputStream(), resultObject);
    } catch (Throwable e) {
        e.printStackTrace();
    } finally {
        System.out.flush();
        System.err.flush();
    }
}

From source file:pl.edu.pwr.iiar.zak.thermalKit.deserializers.HeaterUnitDeserializerTest.java

@Test
public void testDeserializeThermalInstances() throws Exception {
    Method method = HeaterUnitDeserializer.class.getDeclaredMethod("deserializeThermalInstances",
            ArrayNode.class);
    method.setAccessible(true);/* ww w  .java2s  . com*/

    JsonNodeFactory factory = JsonNodeFactory.instance;
    ArrayNode instanceArrayNode = new ArrayNode(factory);
    ObjectNode instanceNode = new ObjectNode(factory);
    instanceArrayNode.add(instanceNode);

    instanceNode.put("name", "upper");
    instanceNode.put("primitiveType", "SLICEL");

    ArrayNode attributeArrayNode = new ArrayNode(factory);
    instanceNode.put("attributes", attributeArrayNode);
    ObjectNode attributeNode = new ObjectNode(factory);
    attributeArrayNode.add(attributeNode);
    attributeNode.put("physicalName", "phyName1");
    attributeNode.put("logicalName", "logName1");
    attributeNode.put("value", "value1");

    ArrayNode enablePinsNode = new ArrayNode(factory);
    instanceNode.put("enablePins", enablePinsNode);
    ObjectNode enablePinNode = new ObjectNode(factory);
    enablePinsNode.add(enablePinNode);
    enablePinNode.put("isOutputPin", false);
    enablePinNode.put("name", "D3");

    System.out.print(instanceArrayNode.toString());

    ArrayList<ThermalInstance> heaterInstances = (ArrayList<ThermalInstance>) method
            .invoke(new HeaterUnitDeserializer(), instanceArrayNode);

    ThermalInstance heaterInstance = heaterInstances.get(0);
    Assert.assertEquals(heaterInstance.getName(), "upper");
    Assert.assertEquals(heaterInstance.getType().toString(), "SLICEL");
}

From source file:edumsg.core.commands.tweet.UnRetweetCommand.java

@Override
public void execute() {
    try {//w w  w  .j  av  a2  s.c o  m
        dbConn = PostgresConnection.getDataSource().getConnection();
        dbConn.setAutoCommit(true);
        proc = dbConn.prepareCall("{? = call unretweet(?,?)}");
        proc.setPoolable(true);
        proc.registerOutParameter(1, Types.INTEGER);
        proc.setInt(2, Integer.parseInt(map.get("tweet_id")));
        proc.setString(3, map.get("session_id"));
        proc.execute();

        int retweets = proc.getInt(1);

        MyObjectMapper mapper = new MyObjectMapper();
        JsonNodeFactory nf = JsonNodeFactory.instance;
        ObjectNode root = nf.objectNode();
        root.put("app", map.get("app"));
        root.put("method", map.get("method"));
        root.put("status", "ok");
        root.put("code", "200");
        root.put("favorites", retweets);
        try {
            CommandsHelp.submit(map.get("app"), mapper.writeValueAsString(root), map.get("correlation_id"),
                    LOGGER);
            String cacheEntry = UserCache.userCache.get("user_tweets:" + map.get("session_id"));
            if (cacheEntry != null) {
                JSONObject cacheEntryJson = new JSONObject(cacheEntry);
                cacheEntryJson.put("cacheStatus", "invalid");
                //                    System.out.println("invalidated");
                UserCache.userCache.set("user_tweets:" + map.get("session_id"), cacheEntryJson.toString());
            }
            String cacheEntry1 = UserCache.userCache.get("timeline:" + map.get("session_id"));
            if (cacheEntry1 != null) {
                JSONObject cacheEntryJson = new JSONObject(cacheEntry1);
                cacheEntryJson.put("cacheStatus", "invalid");
                //                    System.out.println("invalidated");
                UserCache.userCache.set("timeline:" + map.get("session_id"), cacheEntryJson.toString());
            }
            String cacheEntry2 = TweetsCache.tweetCache.get("get_earliest_replies:" + map.get("session_id"));
            if (cacheEntry2 != null) {
                JSONObject cacheEntryJson = new JSONObject(cacheEntry2);
                cacheEntryJson.put("cacheStatus", "invalid");
                //                    System.out.println("invalidated");
                TweetsCache.tweetCache.set("get_earliest_replies:" + map.get("session_id"),
                        cacheEntryJson.toString());
            }
            String cacheEntry3 = TweetsCache.tweetCache.get("get_replies:" + map.get("session_id"));
            if (cacheEntry3 != null) {
                JSONObject cacheEntryJson = new JSONObject(cacheEntry3);
                cacheEntryJson.put("cacheStatus", "invalid");
                //                    System.out.println("invalidated");
                TweetsCache.tweetCache.set("get_replies:" + map.get("session_id"), cacheEntryJson.toString());
            }
            String cacheEntry4 = ListCache.listCache.get("get_list_feeds:" + map.get("session_id"));
            if (cacheEntry4 != null) {
                JSONObject cacheEntryJson = new JSONObject(cacheEntry4);
                cacheEntryJson.put("cacheStatus", "invalid");
                //                    System.out.println("invalidated");
                ListCache.listCache.set("get_list_feeds:" + map.get("session_id"), cacheEntryJson.toString());
            }
        } 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);
        }
        //            catch (JSONException e) {
        //                e.printStackTrace();
        //            }

    } catch (PSQLException e) {
        CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"),
                LOGGER);
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    } catch (SQLException e) {
        CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"),
                LOGGER);
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    } finally {
        PostgresConnection.disconnect(null, proc, dbConn);
    }
}

From source file:net.sf.taverna.t2.activities.rshell.RshellActivityTest.java

@Before
public void setUp() throws Exception {
    Edits edits = new EditsImpl();
    activity = new RshellActivity(null);
    activity.setEdits(new EditsImpl());

    edits.getAddActivityInputPortEdit(activity,
            new ActivityInputPortImpl("example_input", 0, false, null, String.class)).doEdit();
    edits.getAddActivityOutputPortEdit(activity, new ActivityOutputPortImpl("example_output", 0, 0)).doEdit();
    configurationBean = JsonNodeFactory.instance.objectNode();

}

From source file:org.flowable.admin.service.engine.EventSubscriptionService.java

public void triggerExecutionEvent(ServerConfig serverConfig, String eventType, String eventName,
        String executionId) {/*  w w  w .  j a  v a 2s.c  o  m*/
    ObjectNode node = JsonNodeFactory.instance.objectNode();
    if ("message".equals(eventType)) {
        node.put("action", "messageEventReceived");
        node.put("messageName", eventName);

    } else if ("signal".equals(eventType)) {
        node.put("action", "signalEventReceived");
        node.put("signalName", eventName);

    } else {
        throw new FlowableServiceException("Unsupported event type " + eventType);
    }

    HttpPut put = clientUtil.createPut("runtime/executions/" + executionId, serverConfig);
    put.setEntity(clientUtil.createStringEntity(node));

    clientUtil.executeRequest(put, serverConfig);
}

From source file:com.collective.celos.Util.java

public static ObjectNode newObjectNode() {
    return JsonNodeFactory.instance.objectNode();
}