List of usage examples for com.fasterxml.jackson.core JsonParser getCodec
public abstract ObjectCodec getCodec();
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(); 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."); }/*from w w w. j a v a 2 s . c o m*/ 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.orange.clara.cloud.truststore.CertificateJsonDeserializer.java
@Override public List<Certificate> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectMapper mapper = (ObjectMapper) jp.getCodec(); if (jp.getCurrentToken().equals(JsonToken.START_ARRAY)) { final List<String> certificates = mapper.readValue(jp, new TypeReference<List<String>>() { });/*from w w w. j a va 2 s. co m*/ final List<Certificate> collect = certificates.stream().map(e -> CertificateFactory.newInstance(e)) .collect(Collectors.toList()); return collect; } else { //consume this stream mapper.readTree(jp); return new ArrayList<Certificate>(); } }
From source file:de.fraunhofer.iosb.ilt.sta.deserialize.TimeValueDeserializer.java
@Override public TimeValue deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JsonProcessingException { TimeValue result;//from w w w.j a va2 s . c om JsonNode node = jp.getCodec().readTree(jp); try { result = TimeInstant.parse(node.asText()); } catch (Exception e) { result = TimeInterval.parse(node.asText()); } return result; }
From source file:org.mycontroller.standalone.api.jaxrs.mixins.UidTagMixin.java
@Override public UidTag deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectCodec objectCodec = jp.getCodec(); JsonNode node = objectCodec.readTree(jp); final JsonNode sVariableNode = node.get("sensorVariable"); if (node.get("uid") == null || sVariableNode == null || sVariableNode.get("id") == null) { return null; }/*w w w . j a v a 2s .c o m*/ UidTag uidTag = UidTag.builder().uid(node.get("uid").asText()) .sensorVariable(SensorVariable.builder().id(sVariableNode.get("id").asInt()).build()).build(); if (node.get("id") != null) { uidTag.setId(node.get("id").asInt()); } return uidTag; }
From source file:io.gravitee.definition.jackson.datatype.services.healthcheck.deser.HealthCheckDeserializer.java
@Override public HealthCheck deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonNode node = jp.getCodec().readTree(jp); HealthCheck healthCheck = new HealthCheck(); final JsonNode intervalNode = node.get("interval"); if (intervalNode != null) { healthCheck.setInterval(intervalNode.asLong()); } else {// ww w .ja v a 2 s .com throw ctxt.mappingException("[healthcheck] Interval is required"); } final JsonNode unitNode = node.get("unit"); if (unitNode != null) { healthCheck.setUnit(TimeUnit.valueOf(unitNode.asText().toUpperCase())); } else { throw ctxt.mappingException("[healthcheck] Unit is required"); } final JsonNode requestNode = node.get("request"); if (requestNode != null) { healthCheck.setRequest(requestNode.traverse(jp.getCodec()).readValueAs(Request.class)); } else { throw ctxt.mappingException("[healthcheck] Request is required"); } final JsonNode expectationNode = node.get("expectation"); if (expectationNode != null) { healthCheck.setExpectation(expectationNode.traverse(jp.getCodec()).readValueAs(Expectation.class)); } else { Expectation expectation = new Expectation(); expectation.setAssertions(Collections.singletonList(Expectation.DEFAULT_ASSERTION)); healthCheck.setExpectation(expectation); } final JsonNode healthCheckEnabledNode = node.get("enabled"); if (healthCheckEnabledNode != null) { healthCheck.setEnabled(healthCheckEnabledNode.asBoolean(true)); } else { healthCheck.setEnabled(true); } return healthCheck; }
From source file:com.pkrete.locationservice.admin.deserializers.TemplateJSONDeserializer.java
@Override public Template deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); // Parse id/* www .ja v a 2 s. c o m*/ int id = node.get("id") == null ? 0 : node.get("id").intValue(); // Parse filename String filename = node.get("filename") == null ? "" : node.get("filename").textValue(); // Parse language id int languageId = node.get("language_id") == null ? 0 : node.get("language_id").intValue(); // Parse contents String contents = node.get("contents") == null ? null : node.get("contents").textValue(); // Get languagesService bean from Application Context LanguagesService languagesService = (LanguagesService) ApplicationContextUtils.getApplicationContext() .getBean("languagesService"); // Initialize Language variable Language lang = null; // Get Language object if id is not 0 if (languageId != 0) { // Get language object matching the given id lang = languagesService.getLanguageById(languageId); } // Return new Template return new Template(id, filename, "", lang, contents, null); }
From source file:com.pkrete.locationservice.admin.deserializers.MapJSONDeserializer.java
@Override public Map deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); // Get id// w ww .j a v a 2s. c o m int id = node.get("id") == null ? 0 : node.get("id").intValue(); // Get description String description = node.get("description") == null ? "" : node.get("description").textValue(); // Get url String url = node.get("url") == null ? "" : node.get("url").textValue(); // Get filePath String filePath = node.get("file") == null ? "" : node.get("file").textValue(); // Set filePath to null, if length is 0 filePath = filePath.isEmpty() ? null : filePath; // Get color String color = node.get("color") == null ? "" : node.get("color").textValue(); // Get opacity String opacity = node.get("opacity") == null ? "" : node.get("opacity").textValue(); // Create new Map object Map map = new Map(0, url, filePath, description); // Set color map.setColor(color); // Set opacity map.setOpacity(opacity); // Return new map return map; }
From source file:org.calrissian.mango.json.deser.TupleDeserializer.java
@Override public Tuple deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { JsonNode root = jsonParser.getCodec().readTree(jsonParser); String key = root.get("key").asText(); Object value = null;// w w w.ja v a 2s . co m JsonNode type_json = root.get("type"); if (type_json != null) { String type = type_json.asText(); String val_str = root.get("value").asText(); value = typeRegistry.decode(type, val_str); } Map<String, Object> metadata = new HashMap<>(); JsonNode metadataArray = root.get("metadata"); if (metadataArray != null) { for (JsonNode metadataItem : metadataArray) { String metaKey = metadataItem.get("key").asText(); String alias = metadataItem.get("type").asText(); String normalized = metadataItem.get("value").asText(); metadata.put(metaKey, typeRegistry.decode(alias, normalized)); } } return new Tuple(key, value, metadata); }
From source file:piazza.services.ingest.util.GeoJsonDeserializer.java
@Override public Geometry deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { ObjectCodec oc = jp.getCodec(); JsonNode root = oc.readTree(jp);//w w w . ja v a2 s .c o m return parseGeometry(root); }
From source file:com.pkrete.locationservice.admin.deserializers.ShelfJSONDeserializer.java
@Override public Shelf deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); // Create new Shelf object Shelf shelf = new Shelf(); // Deserialize name, locationCode, floor, staffNote1, staffNote2, // map and image variables LocationJSONDeserializerHelper.deserializeBasicGroup1(shelf, node); // Deserialize descriptions and notes variables LocationJSONDeserializerHelper.deserializeDescriptionsAndNotes(shelf, node); // Deserialize areas variable LocationJSONDeserializerHelper.deserializeAreas(shelf, node); // Deserialize subject matters variable LocationJSONDeserializerHelper.deserializeSubjectMatters(shelf, node); // Deserialize shelfNumber String shelfNumber = node.get("shelf_number") == null ? "" : node.get("shelf_number").textValue(); // Set value// ww w . j a va 2s.c o m shelf.setShelfNumber(shelfNumber); // Deserialize collection id int collectionId = node.get("collection_id") == null ? 0 : node.get("collection_id").intValue(); if (collectionId != 0) { shelf.setCollection(new LibraryCollection(collectionId)); } // Return the collection return shelf; }