use of org.codehaus.jackson.JsonProcessingException in project perun by CESNET.
the class JsonSerializerJSONSIMPLE method write.
@Override
public void write(Object object) throws RpcException, IOException {
JsonGenerator gen = jsonFactory.createJsonGenerator(out, JsonEncoding.UTF8);
try {
gen.writeObject(object);
gen.flush();
gen.close();
} catch (JsonProcessingException ex) {
throw new RpcException(RpcException.Type.CANNOT_SERIALIZE_VALUE, ex);
}
}
use of org.codehaus.jackson.JsonProcessingException in project apex-core by apache.
the class StramWebServices method init.
@SuppressWarnings({ "rawtypes", "unchecked" })
private void init() {
//clear content type
httpResponse.setContentType(null);
if (!initialized) {
Map<Class<?>, Class<? extends StringCodec<?>>> codecs = dagManager.getApplicationAttributes().get(DAGContext.STRING_CODECS);
StringCodecs.loadConverters(codecs);
if (codecs != null) {
SimpleModule sm = new SimpleModule("DTSerializationModule", new Version(1, 0, 0, null));
for (Map.Entry<Class<?>, Class<? extends StringCodec<?>>> entry : codecs.entrySet()) {
try {
final StringCodec<Object> codec = (StringCodec<Object>) entry.getValue().newInstance();
sm.addSerializer(new SerializerBase(entry.getKey()) {
@Override
public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
jgen.writeString(codec.toString(value));
}
});
} catch (Exception ex) {
LOG.error("Caught exception when instantiating codec for class {}", entry.getKey().getName(), ex);
}
}
objectMapper.registerModule(sm);
}
initialized = true;
}
}
use of org.codehaus.jackson.JsonProcessingException in project jstorm by alibaba.
the class JSONUtil method equals.
public boolean equals(String firstJSON, String secondJSON) {
try {
JsonNode tree1 = MAPPER.readTree(firstJSON);
JsonNode tree2 = MAPPER.readTree(secondJSON);
boolean areEqual = tree1.equals(tree2);
return areEqual;
} catch (JsonProcessingException e) {
LOGGER.error("json compare wrong:" + firstJSON + ";" + secondJSON, e);
} catch (IOException e) {
LOGGER.error("json compare wrong:" + firstJSON + ";" + secondJSON, e);
}
return false;
}
use of org.codehaus.jackson.JsonProcessingException in project perun by CESNET.
the class JsonSerializerGWT method write.
@Override
public void write(Object object) throws RpcException, IOException {
JsonGenerator gen = jsonFactory.createJsonGenerator(out, JsonEncoding.UTF8);
if (object instanceof Throwable) {
throw new IllegalArgumentException("Tried to serialize a throwable object using write()", (Throwable) object);
}
try {
gen.writeRaw(callback + "(");
gen.writeObject(object);
gen.writeRaw(");");
gen.flush();
gen.close();
} catch (JsonProcessingException ex) {
throw new RpcException(RpcException.Type.CANNOT_SERIALIZE_VALUE, ex);
}
}
use of org.codehaus.jackson.JsonProcessingException in project samza by apache.
the class SamzaObjectMapper method getObjectMapper.
/**
* @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.addDeserializer(Partition.class, new PartitionDeserializer());
module.addDeserializer(SystemStreamPartition.class, new SystemStreamPartitionDeserializer());
module.addKeyDeserializer(SystemStreamPartition.class, new SystemStreamPartitionKeyDeserializer());
module.addDeserializer(Config.class, new ConfigDeserializer());
// 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);
int containerId = node.get("container-id").getIntValue();
if (node.get("container-id") == null) {
throw new SamzaException("JobModel did not contain a container-id. This can never happen. JobModel corrupt!");
}
String processorId;
if (node.get("processor-id") == null) {
processorId = String.valueOf(containerId);
} else {
processorId = node.get("processor-id").getTextValue();
}
Map<TaskName, TaskModel> tasksMapping = OBJECT_MAPPER.readValue(node.get("tasks"), new TypeReference<Map<TaskName, TaskModel>>() {
});
return new ContainerModel(processorId, containerId, tasksMapping);
}
});
// Convert camel case to hyphenated field names, and register the module.
mapper.setPropertyNamingStrategy(new CamelCaseToDashesStrategy());
mapper.registerModule(module);
return mapper;
}
Aggregations