List of usage examples for com.fasterxml.jackson.core JsonParser getCodec
public abstract ObjectCodec getCodec();
From source file:com.wealdtech.jackson.modules.IntervalDeserializer.java
@Override public Interval deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException { final ObjectCodec oc = jsonParser.getCodec(); final JsonNode node = oc.readTree(jsonParser); DateTime start = deserializeDateTime(node, "start"); DateTime end = deserializeDateTime(node, "end"); return new Interval(start, end); }
From source file:org.springframework.security.jackson2.UserDeserializer.java
/** * This method will create {@link User} object. It will ensure successful object creation even if password key is null in * serialized json, because credentials may be removed from the {@link User} by invoking {@link User#eraseCredentials()}. * In that case there won't be any password key in serialized json. */// www .j a v a2 s . c om @Override public User deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectMapper mapper = (ObjectMapper) jp.getCodec(); JsonNode jsonNode = mapper.readTree(jp); Set<GrantedAuthority> authorities = mapper.convertValue(jsonNode.get("authorities"), new TypeReference<Set<SimpleGrantedAuthority>>() { }); return new User(readJsonNode(jsonNode, "username").asText(), readJsonNode(jsonNode, "password").asText(), readJsonNode(jsonNode, "enabled").asBoolean(), readJsonNode(jsonNode, "accountNonExpired").asBoolean(), readJsonNode(jsonNode, "credentialsNonExpired").asBoolean(), readJsonNode(jsonNode, "accountNonLocked").asBoolean(), authorities); }
From source file:org.apache.olingo.commons.core.serialization.JsonDeltaDeserializer.java
protected ResWrap<Delta> doDeserialize(final JsonParser parser) throws IOException { final ObjectNode tree = parser.getCodec().readTree(parser); final DeltaImpl delta = new DeltaImpl(); final URI contextURL = tree.hasNonNull(Constants.JSON_CONTEXT) ? URI.create(tree.get(Constants.JSON_CONTEXT).textValue()) : null;// ww w . java 2s . c om if (contextURL != null) { delta.setBaseURI(StringUtils.substringBefore(contextURL.toASCIIString(), Constants.METADATA)); } if (tree.hasNonNull(jsonCount)) { delta.setCount(tree.get(jsonCount).asInt()); } if (tree.hasNonNull(jsonNextLink)) { delta.setNext(URI.create(tree.get(jsonNextLink).textValue())); } if (tree.hasNonNull(jsonDeltaLink)) { delta.setDeltaLink(URI.create(tree.get(jsonDeltaLink).textValue())); } if (tree.hasNonNull(Constants.VALUE)) { JsonEntityDeserializer entityDeserializer = new JsonEntityDeserializer(version, serverMode); for (JsonNode jsonNode : tree.get(Constants.VALUE)) { final ObjectNode item = (ObjectNode) jsonNode; final ContextURL itemContextURL = item.hasNonNull(Constants.JSON_CONTEXT) ? ContextURLParser.parse(URI.create(item.get(Constants.JSON_CONTEXT).textValue())) : null; item.remove(Constants.JSON_CONTEXT); if (itemContextURL == null || itemContextURL.isEntity()) { delta.getEntities() .add(entityDeserializer.doDeserialize(item.traverse(parser.getCodec())).getPayload()); } else if (itemContextURL.isDeltaDeletedEntity()) { delta.getDeletedEntities().add(parser.getCodec().treeToValue(item, DeletedEntityImpl.class)); } else if (itemContextURL.isDeltaLink()) { delta.getAddedLinks().add(parser.getCodec().treeToValue(item, DeltaLinkImpl.class)); } else if (itemContextURL.isDeltaDeletedLink()) { delta.getDeletedLinks().add(parser.getCodec().treeToValue(item, DeltaLinkImpl.class)); } } } return new ResWrap<Delta>(contextURL, null, delta); }
From source file:org.dswarm.common.model.deserializer.ContentSchemaDeserializer.java
@Override public ContentSchema deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException { final ObjectCodec oc = jp.getCodec(); if (oc == null) { return null; }//from www . j a v a2 s.c o m final JsonNode node = oc.readTree(jp); if (node == null) { return null; } final JsonNode recordIdentifierAttributePathNode = node.get("record_identifier_attribute_path"); final AttributePath recordIdentifierAttributePath = AttributePathUtil .parseAttributePathNode(recordIdentifierAttributePathNode, attributeMap, attributePathMap); final JsonNode keyAttributePathsNode = node.get("key_attribute_paths"); final LinkedList<AttributePath> keyAttributePaths = AttributePathUtil .parseAttributePathsNode(keyAttributePathsNode, attributeMap, attributePathMap); final JsonNode valueAttributePathNode = node.get("value_attribute_path"); final AttributePath valueAttributePath = AttributePathUtil.parseAttributePathNode(valueAttributePathNode, attributeMap, attributePathMap); return new ContentSchema(recordIdentifierAttributePath, keyAttributePaths, valueAttributePath); }
From source file:org.apache.olingo.client.core.serialization.JsonDeltaDeserializer.java
protected ResWrap<Delta> doDeserialize(final JsonParser parser) throws IOException { final ObjectNode tree = parser.getCodec().readTree(parser); final Delta delta = new Delta(); final URI contextURL = tree.hasNonNull(Constants.JSON_CONTEXT) ? URI.create(tree.get(Constants.JSON_CONTEXT).textValue()) : null;/*from www.ja v a 2s. c o m*/ if (contextURL != null) { delta.setBaseURI( URI.create(StringUtils.substringBefore(contextURL.toASCIIString(), Constants.METADATA))); } if (tree.hasNonNull(Constants.JSON_COUNT)) { delta.setCount(tree.get(Constants.JSON_COUNT).asInt()); } if (tree.hasNonNull(Constants.JSON_NEXT_LINK)) { delta.setNext(URI.create(tree.get(Constants.JSON_NEXT_LINK).textValue())); } if (tree.hasNonNull(Constants.JSON_DELTA_LINK)) { delta.setDeltaLink(URI.create(tree.get(Constants.JSON_DELTA_LINK).textValue())); } if (tree.hasNonNull(Constants.VALUE)) { JsonEntityDeserializer entityDeserializer = new JsonEntityDeserializer(serverMode); for (JsonNode jsonNode : tree.get(Constants.VALUE)) { final ObjectNode item = (ObjectNode) jsonNode; final ContextURL itemContextURL = item.hasNonNull(Constants.JSON_CONTEXT) ? ContextURLParser.parse(URI.create(item.get(Constants.JSON_CONTEXT).textValue())) : null; item.remove(Constants.JSON_CONTEXT); if (itemContextURL == null || itemContextURL.isEntity()) { delta.getEntities() .add(entityDeserializer.doDeserialize(item.traverse(parser.getCodec())).getPayload()); } else if (itemContextURL.isDeltaDeletedEntity()) { delta.getDeletedEntities().add(parser.getCodec().treeToValue(item, DeletedEntity.class)); } else if (itemContextURL.isDeltaLink()) { delta.getAddedLinks().add(parser.getCodec().treeToValue(item, DeltaLink.class)); } else if (itemContextURL.isDeltaDeletedLink()) { delta.getDeletedLinks().add(parser.getCodec().treeToValue(item, DeltaLink.class)); } } } return new ResWrap<Delta>(contextURL, null, delta); }
From source file:io.realm.examples.newsreader.model.network.RealmListNYTimesMultimediumDeserializer.java
@Override public List<NYTimesMultimedium> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { RealmList<NYTimesMultimedium> list = new RealmList<>(); TreeNode treeNode = jp.getCodec().readTree(jp); if (!(treeNode instanceof ArrayNode)) { return list; }//from w w w.ja v a 2s . c om ArrayNode arrayNode = (ArrayNode) treeNode; for (JsonNode node : arrayNode) { NYTimesMultimedium nyTimesMultimedium = objectMapper.treeToValue(node, NYTimesMultimedium.class); list.add(nyTimesMultimedium); } return list; }
From source file:io.gravitee.definition.jackson.datatype.api.deser.RuleDeserializer.java
@Override public Rule deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonNode node = jp.getCodec().readTree(jp); Rule rule = new Rule(); node.fieldNames().forEachRemaining(field -> { JsonNode subNode = node.findValue(field); switch (field) { case "methods": if (subNode != null && subNode.isArray()) { HttpMethod[] methods = new HttpMethod[subNode.size()]; final int[] idx = { 0 }; subNode.elements().forEachRemaining(jsonNode -> { methods[idx[0]++] = HttpMethod.valueOf(jsonNode.asText().toUpperCase()); });/* w ww.ja va 2 s. com*/ rule.getMethods().addAll(Arrays.asList(methods)); } break; case "description": if (subNode != null) { rule.setDescription(subNode.asText()); } break; case "enabled": if (subNode != null) { rule.setEnabled(subNode.asBoolean(true)); } break; default: // We are in the case of a policy Policy policy = new Policy(); policy.setName(field); policy.setConfiguration(subNode.toString()); rule.setPolicy(policy); break; } }); if (rule.getMethods().isEmpty()) { rule.getMethods() .addAll(Arrays.asList(HttpMethod.CONNECT, HttpMethod.DELETE, HttpMethod.GET, HttpMethod.HEAD, HttpMethod.OPTIONS, HttpMethod.PATCH, HttpMethod.POST, HttpMethod.PUT, HttpMethod.TRACE)); } return rule; }
From source file:io.swagger.inflector.processors.JsonExampleDeserializer.java
@Override public Example deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { Example output = null;/*from ww w.ja v a 2 s. c om*/ JsonNode node = jp.getCodec().readTree(jp); if (node instanceof ObjectNode) { ObjectExample obj = new ObjectExample(); ObjectNode on = (ObjectNode) node; for (Iterator<Entry<String, JsonNode>> x = on.fields(); x.hasNext();) { Entry<String, JsonNode> i = x.next(); String key = i.getKey(); JsonNode value = i.getValue(); obj.put(key, new StringExample(value.asText())); output = obj; } } else if (node instanceof TextNode) { output = new StringExample(((TextNode) node).asText()); } return output; }
From source file:org.mycontroller.standalone.api.jaxrs.mixins.deserializers.SensorTypeDeserializer.java
@Override public MESSAGE_TYPE_PRESENTATION deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException { final LocaleString localeString = OBJECT_MAPPER.treeToValue(parser.getCodec().readTree(parser), LocaleString.class); if (localeString != null && localeString.getEn() != null) { return MESSAGE_TYPE_PRESENTATION.fromString(localeString.getEn()); } else {/*from w ww .jav a 2 s. c o m*/ return null; } }
From source file:org.apache.olingo.client.core.data.JSONServiceDocumentDeserializer.java
protected ResWrap<ServiceDocument> doDeserialize(final JsonParser parser) throws IOException { final ObjectNode tree = parser.getCodec().readTree(parser); ServiceDocumentImpl serviceDocument = new ServiceDocumentImpl(); final String metadataETag; if (tree.hasNonNull(Constants.JSON_METADATA_ETAG)) { metadataETag = tree.get(Constants.JSON_METADATA_ETAG).textValue(); tree.remove(Constants.JSON_METADATA_ETAG); } else {//from w w w .j a v a 2 s . c o m metadataETag = null; } final URI contextURL; if (tree.hasNonNull(Constants.JSON_CONTEXT)) { contextURL = URI.create(tree.get(Constants.JSON_CONTEXT).textValue()); tree.remove(Constants.JSON_CONTEXT); } else if (tree.hasNonNull(Constants.JSON_METADATA)) { contextURL = URI.create(tree.get(Constants.JSON_METADATA).textValue()); tree.remove(Constants.JSON_METADATA); } else { contextURL = null; } serviceDocument.setMetadata(contextURL == null ? null : contextURL.toASCIIString()); for (final Iterator<JsonNode> itor = tree.get(Constants.VALUE).elements(); itor.hasNext();) { final JsonNode node = itor.next(); final ServiceDocumentItemImpl item = new ServiceDocumentItemImpl(); item.setName(node.get("name").asText()); JsonNode titleNode = node.get("title"); if (titleNode != null) { item.setTitle(titleNode.asText()); } item.setUrl(node.get("url").asText()); final String kind = node.has("kind") ? node.get("kind").asText() : null; if (StringUtils.isBlank(kind) || "EntitySet".equals(kind)) { serviceDocument.getEntitySets().add(item); } else if ("Singleton".equals(kind)) { serviceDocument.getSingletons().add(item); } else if ("FunctionImport".equals(kind)) { serviceDocument.getFunctionImports().add(item); } else if ("ServiceDocument".equals(kind)) { serviceDocument.getRelatedServiceDocuments().add(item); } } return new ResWrap<ServiceDocument>(contextURL, metadataETag, serviceDocument); }