List of usage examples for com.fasterxml.jackson.databind.node ObjectNode get
public JsonNode get(String paramString)
From source file:com.redhat.lightblue.crud.DocRequest.java
/** * Parses the entitydata from the given Json object *///from ww w . ja va2s . co m @Override protected void parse(ObjectNode node) { super.parse(node); entityData = node.get("data"); }
From source file:com.evrythng.java.wrapper.mapping.TypeMapDeserializer.java
@Override public T deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException { ObjectCodec codec = jp.getCodec();/*from w ww. ja v a 2 s . c om*/ ObjectMapper mapper = (ObjectMapper) codec; ObjectNode root = mapper.readTree(jp); JsonNode type = root.get(typeFieldName); final String sType = type == null ? null : type.textValue(); Class<? extends T> clazz = resolveClass(sType); return codec.treeToValue(root, clazz); }
From source file:io.syndesis.model.integration.StepDeserializer.java
@Override public Step deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { ObjectNode node = jp.readValueAsTree(); JsonNode stepKind = node.get(STEP_KIND); if (stepKind != null) { String value = stepKind.textValue(); Class<? extends Step> resourceType = getTypeForName(value); if (resourceType == null) { throw ctxt.mappingException("No step type found for kind:" + value); } else {/*from w w w . j a v a2 s. co m*/ return jp.getCodec().treeToValue(node, resourceType); } } return null; }
From source file:com.jivesoftware.jive.deployer.jaxrs.util.ResponseHelperTest.java
@Test public void testErrorResponse() throws Exception { ObjectNode jsonNode = objectMapper.createObjectNode(); jsonNode.put("Foobar", true); String message = "This is a BAD request!"; Exception e = new Exception(); OutputStream outputStream = new ByteArrayOutputStream(); PrintStream printStream = new PrintStream(outputStream); e.printStackTrace(printStream);// www .j a v a 2s . co m Response response = ResponseHelper.INSTANCE.errorResponse(Response.Status.BAD_REQUEST, message, e, jsonNode); assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode()); String bodyString = objectMapper.writeValueAsString(response.getEntity()); System.out.println(bodyString); ObjectNode body = (ObjectNode) objectMapper.readTree(bodyString); assertEquals(body.get("message").textValue(), message); assertEquals(body.get("trace").textValue(), outputStream.toString()); assertEquals(body.get("relatedData"), jsonNode); }
From source file:com.almende.eve.monitor.Cache.java
/** * Returns if cached result passes filter data. Default implementation * supports filtering on value age:/*w ww . ja v a 2 s. c o m*/ * * { "maxAge":1000 } - example: Max age is one second. * * @param params * the params * @return true, if successful */ public boolean filter(final ObjectNode params) { if (!params.has("maxAge") || !params.get("maxAge").isInt() || stored == null) { return false; } return stored.plusMillis(params.get("maxAge").intValue()).isAfterNow(); }
From source file:com.evrythng.java.wrapper.mapping.GeoJsonDeserializerImpl.java
@Override public GeoJson deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectCodec codec = jp.getCodec();//from ww w . j a va 2 s. c o m ObjectMapper mapper = (ObjectMapper) codec; ObjectNode root = (ObjectNode) mapper.readTree(jp); JsonNode type = root.get(getTypeFieldName()); if (type == null) { throw new IllegalArgumentException(this.getValueClass().getSimpleName() + " type cannot be empty."); } String sType = type.textValue(); if (sType == null || sType.isEmpty()) { throw new IllegalArgumentException(this.getValueClass().getSimpleName() + " type cannot be empty."); } Class<GeoJson> clazz = (Class<GeoJson>) resolveClass(sType); GeoJson obj = codec.treeToValue(root, clazz); if (obj == null) { throw new IllegalArgumentException( this.getValueClass().getSimpleName() + " type deserialised as null: " + root.toString()); } return obj; }
From source file:com.basistech.rosette.dm.json.plain.LanguageCodeJsonTest.java
@Test public void testRoundTrip() throws Exception { List<LanguageDetection.DetectionResult> detectionResults = Lists.newArrayList(); LanguageDetection.DetectionResult detectionResult = new LanguageDetection.DetectionResult.Builder( LanguageCode.KOREAN).encoding("uff-8").script(ISO15924.Hang).confidence(1.0).build(); detectionResults.add(detectionResult); LanguageDetection.Builder builder = new LanguageDetection.Builder(0, 100, detectionResults); LanguageDetection languageDetection = builder.build(); ObjectMapper mapper = objectMapper(); String json = mapper.writeValueAsString(languageDetection); // now read back as a tree. JsonNode tree = mapper.readTree(json); JsonNode resultsNode = tree.get("detectionResults"); ArrayNode resultArray = (ArrayNode) resultsNode; ObjectNode detectionNode = (ObjectNode) resultArray.get(0); assertEquals("kor", detectionNode.get("language").textValue()); assertEquals("Hang", detectionNode.get("script").textValue()); languageDetection = mapper.readValue(json, LanguageDetection.class); assertSame(LanguageCode.KOREAN, languageDetection.getDetectionResults().get(0).getLanguage()); }
From source file:com.syncedsynapse.kore2.jsonrpc.ApiException.java
/** * Construct exception from JSON response * @param code Exception code//w ww. j a va 2 s. co m * @param jsonResponse Json response, with an Error node */ public ApiException(int code, ObjectNode jsonResponse) { super((jsonResponse.get(ApiMethod.ERROR_NODE) != null) ? JsonUtils.stringFromJsonNode(jsonResponse.get(ApiMethod.ERROR_NODE), "message") : "No message returned"); this.code = code; }
From source file:org.forgerock.openig.migrate.action.HandlerObjectAction.java
@Override public ObjectNode migrate(final ObjectNode configuration) { if (configuration.has("handlerObject")) { configuration.set("handler", configuration.get("handlerObject")); configuration.remove("handlerObject"); }//ww w .java 2s .c o m return configuration; }
From source file:enmasse.controller.api.v3.amqp.AmqpFlavorsApiTest.java
@Test public void testGet() throws IOException { Message response = doRequest("GET", "", Optional.of("flavor1")); ObjectNode data = decodeJson(response); assertThat(data.get("kind").asText(), is("Flavor")); assertThat(data.get("metadata").get("name").asText(), is("flavor1")); assertThat(data.get("spec").get("type").asText(), is("queue")); assertThat(data.get("spec").get("description").asText(), is("Simple queue")); }