org.codehaus.jackson.ObjectCodec Java Examples
The following examples show how to use
org.codehaus.jackson.ObjectCodec.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JsonUpdateWebServer.java From jwala with Apache License 2.0 | 6 votes |
@Override public JsonUpdateWebServer deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException { final ObjectCodec obj = jp.getCodec(); final JsonNode node = obj.readTree(jp).get(0); final Set<String> groupIds = deserializeGroupIdentifiers(node); return new JsonUpdateWebServer(node.get("webserverId").getValueAsText(), node.get("webserverName").getTextValue(), node.get("hostName").getTextValue(), node.get("portNumber").getValueAsText(), node.get("httpsPort").getValueAsText(), groupIds, node.get("statusPath").getTextValue(), node.get("apacheHttpdMediaId").getTextValue()); }
Example #2
Source File: JsonCreateWebServer.java From jwala with Apache License 2.0 | 6 votes |
@Override public JsonCreateWebServer deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException { final ObjectCodec obj = jp.getCodec(); final JsonNode node = obj.readTree(jp).get(0); final JsonNode apacheHttpdMediaId = node.get("apacheHttpdMediaId"); final JsonCreateWebServer jcws = new JsonCreateWebServer(node.get("webserverName").getTextValue(), node.get("hostName").getTextValue(), node.get("portNumber").asText(), node.get("httpsPort").asText(), deserializeGroupIdentifiers(node), node.get("statusPath").getTextValue(), apacheHttpdMediaId == null ? null : apacheHttpdMediaId.asText()); return jcws; }
Example #3
Source File: ContainerPlacementMessageObjectMapper.java From samza with Apache License 2.0 | 5 votes |
@Override public ContainerPlacementMessage deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); String subType = node.get("subType").getTextValue(); String deploymentId = node.get("deploymentId").getTextValue(); String processorId = node.get("processorId").getTextValue(); String destinationHost = node.get("destinationHost").getTextValue(); long timestamp = node.get("timestamp").getLongValue(); Duration requestExpiry = node.get("requestExpiry") == null ? null : Duration.ofMillis(node.get("requestExpiry").getLongValue()); ContainerPlacementMessage.StatusCode statusCode = null; UUID uuid = UUID.fromString(node.get("uuid").getTextValue()); for (ContainerPlacementMessage.StatusCode code : ContainerPlacementMessage.StatusCode.values()) { if (code.name().equals(node.get("statusCode").getTextValue())) { statusCode = code; } } ContainerPlacementMessage message = null; if (subType.equals(ContainerPlacementRequestMessage.class.getSimpleName())) { message = new ContainerPlacementRequestMessage(uuid, deploymentId, processorId, destinationHost, requestExpiry, timestamp); } else if (subType.equals(ContainerPlacementResponseMessage.class.getSimpleName())) { String responseMessage = node.get("responseMessage").getTextValue(); message = new ContainerPlacementResponseMessage(uuid, deploymentId, processorId, destinationHost, requestExpiry, statusCode, responseMessage, timestamp); } return message; }
Example #4
Source File: CustomFieldDeSerializer.java From jira-rest-client with Apache License 2.0 | 5 votes |
@Override public Object deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { logger.info("Deserialize..."); ObjectCodec oc = jp.getCodec(); JsonNode node = oc.readTree(jp); for (int i = 0; i < node.size(); i++) { JsonNode child = node.get(i); if (child == null) { logger.info(i + "th Child node is null"); continue; } //String if (child.isTextual()) { Iterator<String> it = child.getFieldNames(); while (it.hasNext()) { String field = it.next(); logger.info("in while loop " + field); if (field.startsWith("customfield")) { } } } } return null; }
Example #5
Source File: SamzaObjectMapper.java From samza with Apache License 2.0 | 5 votes |
@Override public SystemStreamPartition deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException, JsonProcessingException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); String system = node.get("system").getTextValue(); String stream = node.get("stream").getTextValue(); Partition partition = new Partition(node.get("partition").getIntValue()); return new SystemStreamPartition(system, stream, partition); }
Example #6
Source File: SamzaObjectMapper.java From samza with Apache License 2.0 | 5 votes |
@Override public TaskMode deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException, JsonProcessingException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); if (node == null || node.getTextValue().equals("")) { return TaskMode.Active; } else { return TaskMode.valueOf(node.getTextValue()); } }
Example #7
Source File: SamzaObjectMapper.java From samza with Apache License 2.0 | 5 votes |
@Override public Config deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException, JsonProcessingException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); return new MapConfig(OBJECT_MAPPER.<Map<String, String>>readValue(node, new TypeReference<Map<String, String>>() { })); }
Example #8
Source File: RuleJsonDeserializer.java From urule with Apache License 2.0 | 5 votes |
@Override public List<Rule> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectCodec oc = jp.getCodec(); JsonNode jsonNode = oc.readTree(jp); Iterator<JsonNode> childrenNodesIter=jsonNode.getElements(); List<Rule> rules=new ArrayList<Rule>(); while(childrenNodesIter.hasNext()){ JsonNode childNode=childrenNodesIter.next(); rules.add(parseRule(jp,childNode)); } return rules; }
Example #9
Source File: JsonControlWebServer.java From jwala with Apache License 2.0 | 5 votes |
@Override public JsonControlWebServer deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException { final ObjectCodec obj = jp.getCodec(); final JsonNode rootNode = obj.readTree(jp); final JsonNode operation = rootNode.get("controlOperation"); return new JsonControlWebServer(operation.getTextValue()); }
Example #10
Source File: JsonControlGroup.java From jwala with Apache License 2.0 | 5 votes |
@Override public JsonControlGroup deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException { final ObjectCodec obj = jp.getCodec(); final JsonNode rootNode = obj.readTree(jp); final JsonNode operation = rootNode.get("controlOperation"); return new JsonControlGroup(operation.getTextValue()); }
Example #11
Source File: JsonJvms.java From jwala with Apache License 2.0 | 5 votes |
@Override public JsonJvms deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException { final ObjectCodec obj = jp.getCodec(); final JsonNode rootNode = obj.readTree(jp); final Set<String> rawJvmIds = deserializeJvmIdentifiers(rootNode); return new JsonJvms(rawJvmIds); }
Example #12
Source File: JsonUpdateGroup.java From jwala with Apache License 2.0 | 5 votes |
@Override public JsonUpdateGroup deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException { final ObjectCodec obj = jp.getCodec(); final JsonNode node = obj.readTree(jp); return new JsonUpdateGroup(node.get("id").getTextValue(), node.get("name").getTextValue()); }
Example #13
Source File: JsonControlJvm.java From jwala with Apache License 2.0 | 5 votes |
@Override public JsonControlJvm deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException { final ObjectCodec obj = jp.getCodec(); final JsonNode rootNode = obj.readTree(jp); final JsonNode operation = rootNode.get("controlOperation"); return new JsonControlJvm(operation.getTextValue()); }
Example #14
Source File: SamzaObjectMapper.java From samza with Apache License 2.0 | 4 votes |
/** * @return Returns a new ObjectMapper that's been configured to (de)serialize * Samza's job data model, and simple data types such as TaskName, * Partition, Config, and SystemStreamPartition. */ public static ObjectMapper getObjectMapper() { ObjectMapper mapper = new ObjectMapper(); SimpleModule module = new SimpleModule("SamzaModule", new Version(1, 0, 0, "")); // Setup custom serdes for simple data types. module.addSerializer(Partition.class, new PartitionSerializer()); module.addSerializer(SystemStreamPartition.class, new SystemStreamPartitionSerializer()); module.addKeySerializer(SystemStreamPartition.class, new SystemStreamPartitionKeySerializer()); module.addSerializer(TaskName.class, new TaskNameSerializer()); module.addSerializer(TaskMode.class, new TaskModeSerializer()); module.addDeserializer(TaskName.class, new TaskNameDeserializer()); module.addDeserializer(Partition.class, new PartitionDeserializer()); module.addDeserializer(SystemStreamPartition.class, new SystemStreamPartitionDeserializer()); module.addKeyDeserializer(SystemStreamPartition.class, new SystemStreamPartitionKeyDeserializer()); module.addDeserializer(Config.class, new ConfigDeserializer()); module.addDeserializer(TaskMode.class, new TaskModeDeserializer()); // Setup mixins for data models. mapper.getSerializationConfig().addMixInAnnotations(TaskModel.class, JsonTaskModelMixIn.class); mapper.getDeserializationConfig().addMixInAnnotations(TaskModel.class, JsonTaskModelMixIn.class); mapper.getSerializationConfig().addMixInAnnotations(ContainerModel.class, JsonContainerModelMixIn.class); mapper.getSerializationConfig().addMixInAnnotations(JobModel.class, JsonJobModelMixIn.class); mapper.getDeserializationConfig().addMixInAnnotations(JobModel.class, JsonJobModelMixIn.class); module.addDeserializer(ContainerModel.class, new JsonDeserializer<ContainerModel>() { @Override public ContainerModel deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectCodec oc = jp.getCodec(); JsonNode node = oc.readTree(jp); /* * Before Samza 0.13, "container-id" was used. * In Samza 0.13, "processor-id" was added to be the id to use and "container-id" was deprecated. However, * "container-id" still needed to be checked for backwards compatibility in case "processor-id" was missing * (i.e. from a job model corresponding to a version of the job that was on a pre Samza 0.13 version). * In Samza 1.0, "container-id" was further cleaned up from ContainerModel. This logic is still being left here * as a fallback for backwards compatibility with pre Samza 0.13. ContainerModel.getProcessorId was changed to * ContainerModel.getId in the Java API, but "processor-id" still needs to be used as the JSON key for backwards * compatibility with Samza 0.13 and Samza 0.14. */ String id; if (node.get(JsonContainerModelMixIn.PROCESSOR_ID_KEY) == null) { if (node.get(JsonContainerModelMixIn.CONTAINER_ID_KEY) == null) { throw new SamzaException( String.format("JobModel was missing %s and %s. This should never happen. JobModel corrupt!", JsonContainerModelMixIn.PROCESSOR_ID_KEY, JsonContainerModelMixIn.CONTAINER_ID_KEY)); } id = String.valueOf(node.get(JsonContainerModelMixIn.CONTAINER_ID_KEY).getIntValue()); } else { id = node.get(JsonContainerModelMixIn.PROCESSOR_ID_KEY).getTextValue(); } Map<TaskName, TaskModel> tasksMapping = OBJECT_MAPPER.readValue(node.get(JsonContainerModelMixIn.TASKS_KEY), new TypeReference<Map<TaskName, TaskModel>>() { }); return new ContainerModel(id, tasksMapping); } }); // Convert camel case to hyphenated field names, and register the module. mapper.setPropertyNamingStrategy(new CamelCaseToDashesStrategy()); mapper.registerModule(module); return mapper; }
Example #15
Source File: SamzaObjectMapper.java From samza with Apache License 2.0 | 4 votes |
@Override public Partition deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException, JsonProcessingException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); return new Partition(node.getIntValue()); }
Example #16
Source File: SamzaObjectMapper.java From samza with Apache License 2.0 | 4 votes |
@Override public TaskName deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException, JsonProcessingException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); return new TaskName(node.getTextValue()); }
Example #17
Source File: GenericServiceAPIResponseEntityDeserializer.java From Eagle with Apache License 2.0 | 4 votes |
@Override public GenericServiceAPIResponseEntity deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { GenericServiceAPIResponseEntity entity = new GenericServiceAPIResponseEntity(); ObjectCodec objectCodec = jp.getCodec(); JsonNode rootNode = jp.getCodec().readTree(jp); if(rootNode.isObject()){ Iterator<Map.Entry<String,JsonNode>> fields = rootNode.getFields(); JsonNode objNode = null; while(fields.hasNext()){ Map.Entry<String,JsonNode> field = fields.next(); if (META_FIELD.equals(field.getKey()) && field.getValue() != null) entity.setMeta(objectCodec.readValue(field.getValue().traverse(), Map.class)); else if(SUCCESS_FIELD.equals(field.getKey()) && field.getValue() != null){ entity.setSuccess(field.getValue().getValueAsBoolean(false)); }else if(EXCEPTION_FIELD.equals(field.getKey()) && field.getValue() != null){ entity.setException(field.getValue().getTextValue()); }else if(TYPE_FIELD.endsWith(field.getKey()) && field.getValue() != null){ try { entity.setType(Class.forName(field.getValue().getTextValue())); } catch (ClassNotFoundException e) { throw new IOException(e); } }else if(OBJ_FIELD.equals(field.getKey()) && field.getValue() != null){ objNode = field.getValue(); } } if(objNode!=null) { JavaType collectionType=null; if (entity.getType() != null) { collectionType = TypeFactory.defaultInstance().constructCollectionType(LinkedList.class, entity.getType()); }else{ collectionType = TypeFactory.defaultInstance().constructCollectionType(LinkedList.class, Map.class); } List obj = objectCodec.readValue(objNode.traverse(), collectionType); entity.setObj(obj); } }else{ throw new IOException("root node is not object"); } return entity; }