List of usage examples for com.fasterxml.jackson.core ObjectCodec readTree
public abstract <T extends TreeNode> T readTree(JsonParser jp) throws IOException, JsonProcessingException;
From source file:org.lable.rfc3881.auditlogger.serialization.CodeReferenceDeserializer.java
@Override public CodeReference deserialize(JsonParser parser, DeserializationContext context) throws IOException { ObjectCodec oc = parser.getCodec(); JsonNode node = oc.readTree(parser); // Required fields. if (!node.has("cs") || !node.has("code") || !node.has("dn")) { return null; }// w ww.j a v a2 s. c o m String codeSystem = node.get("cs").asText(null); String code = node.get("code").asText(null); String displayName = node.get("dn").asText(null); // Optional fields, can be null. String codeSystemName = node.has("csn") ? node.get("csn").asText(null) : null; String originalText = node.has("ot") ? node.get("ot").asText(null) : null; return new CodeReference(codeSystem, codeSystemName, code, displayName, originalText); }
From source file:com.pkrete.locationservice.admin.deserializers.CSSJSONDeserializer.java
@Override public CSS deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); // Parse id/*from 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 contents String contents = node.get("contents") == null ? null : node.get("contents").textValue(); // Return new CSS return new CSS(id, filename, "", contents, null); }
From source file:com.wealdtech.jackson.modules.DateTimeZoneDeserializer.java
@Override public DateTimeZone deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException { final ObjectCodec oc = jsonParser.getCodec(); final JsonNode node = oc.readTree(jsonParser); DateTimeZone result;/*ww w.jav a 2 s . c o m*/ try { result = DateTimeZone.forID(node.textValue()); } catch (IllegalArgumentException iae) { LOGGER.warn("Attempt to deserialize invalid datetimezone {}", node.textValue()); throw new IOException("Invalid datetimezone value \"" + node.textValue() + "\"", iae); } return result; }
From source file:org.atomspace.camel.component.tinkerforge.generator.databind.ElementsDeserializer.java
@Override public Elements deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectCodec oc = jp.getCodec(); JsonNode jsonNode = oc.readTree(jp); Elements elements = new Elements(); for (JsonNode jsonElement : jsonNode) { Element element = new Element(); element.name = jsonElement.get(0).asText(); element.type = jsonElement.get(1).asText(); element.num = jsonElement.get(2).asInt(); element.inout = jsonElement.get(3).asText(); elements.add(element);/*from w w w.j a v a2 s .c om*/ } return elements; }
From source file:com.wealdtech.jackson.modules.LocalDateTimeDeserializer.java
@Override public LocalDateTime deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException { final ObjectCodec oc = jsonParser.getCodec(); final JsonNode node = oc.readTree(jsonParser); try {/* w w w . jav a 2 s . c om*/ return formatter.parseDateTime(node.textValue()).withZone(DateTimeZone.UTC).toLocalDateTime(); } catch (IllegalArgumentException iae) { LOGGER.warn("Attempt to deserialize invalid localdatetime {}", node.textValue()); throw new IOException("Invalid localdatetime value \"" + node.textValue() + "\"", iae); } }
From source file:com.btmatthews.atlas.core.domain.i18n.LocalizedDeserializer.java
@Override public Localized deserialize(final JsonParser parser, final DeserializationContext context) throws IOException { final LocalizedBuilder<Object> builder = new LocalizedBuilder<>(); final ObjectCodec codec = parser.getCodec(); final JsonNode node = codec.readTree(parser); final Iterator<Map.Entry<String, JsonNode>> iterator = node.fields(); while (iterator.hasNext()) { final Map.Entry<String, JsonNode> entry = iterator.next(); builder.setValue(Locale.forLanguageTag(entry.getKey()), entry.getValue().textValue()); }// w w w. ja va2 s . c om return builder.build(); }
From source file:com.wavemaker.commons.json.deserializer.HttpHeadersDeSerializer.java
@Override public HttpHeaders deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { ObjectCodec codec = jp.getCodec(); ObjectNode root = codec.readTree(jp); Map<String, Object> map = ((ObjectMapper) codec).readValue(root.toString(), new TypeReference<LinkedHashMap<String, Object>>() { });/*from ww w . j a v a 2s .c om*/ HttpHeaders httpHeaders = new HttpHeaders(); for (Map.Entry<String, Object> entry : map.entrySet()) { Object value = entry.getValue(); if (value instanceof String) { httpHeaders.add(entry.getKey(), (String) entry.getValue()); } else if (value instanceof List) { httpHeaders.put(entry.getKey(), (List<String>) value); } } return httpHeaders; }
From source file:com.wealdtech.jackson.modules.LocalDateDeserializer.java
@Override public LocalDate deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException { final ObjectCodec oc = jsonParser.getCodec(); final JsonNode node = oc.readTree(jsonParser); LocalDate result = null;/*from w ww . java 2 s .c om*/ try { result = formatter.parseLocalDate(node.textValue()); } catch (IllegalArgumentException iae) { LOGGER.warn("Attempt to deserialize invalid localdate {}", node.textValue()); throw new IOException("Invalid localdate value \"" + node.textValue() + "\"", iae); } return result; }
From source file:com.pkrete.locationservice.admin.deserializers.ImageJSONDeserializer.java
@Override public Image deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); // Get id/*from w w w . 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; // Return new image return new Image(0, url, filePath, description); }
From source file:com.wealdtech.jackson.modules.PeriodDeserializer.java
@Override public Period deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException { final ObjectCodec oc = jsonParser.getCodec(); final JsonNode node = oc.readTree(jsonParser); Period result = null;//from w w w . j a v a 2 s .c om try { result = formatter.parsePeriod(node.textValue()); } catch (IllegalArgumentException iae) { LOGGER.warn("Attempt to deserialize invalid period {}", node.textValue()); throw new IOException("Invalid period value", iae); } return result; }