deserialization

Deserialize mutable (primitive/object) JSON property to object with Jackson

自闭症网瘾萝莉.ら 提交于 2021-01-29 04:04:46
问题 Given a JSON object having a mutable property (e.g. label ) which can be either primitive value (e.g. string) or an object. A hypothetical use-case could be a wrapper for pluralized translation of a label: { "label": "User name" } or { "label": { "one": "A label", "other": "The labels" } } The goal is to bring Jackson deserialization always return a fixed structure on the Java-side. Thus, if a primitive value is given it is always translated to a certain property (e.g. other ) of the target

Returning a dynamic object is throwing runtime error

浪尽此生 提交于 2021-01-28 17:03:24
问题 I am developing a Web API, where the GET method needs to return an object, whose variables will be decided based on an XML file. The returned format must be either XML or JSON as requested by the client. I want to return the data inside XML file into XML format to the client, and something reasonable for JSON when JSON is requested. The nodes in the XML might increase or decrease and therefore I cannot define a fixed class in the Models . My current solution is to return a dynamic object, but

Returning a dynamic object is throwing runtime error

霸气de小男生 提交于 2021-01-28 17:02:48
问题 I am developing a Web API, where the GET method needs to return an object, whose variables will be decided based on an XML file. The returned format must be either XML or JSON as requested by the client. I want to return the data inside XML file into XML format to the client, and something reasonable for JSON when JSON is requested. The nodes in the XML might increase or decrease and therefore I cannot define a fixed class in the Models . My current solution is to return a dynamic object, but

Why Jackson JSON mapping exception when Serializing/Deserializing Geometry type

依然范特西╮ 提交于 2021-01-28 11:59:56
问题 When I create a User defined class "Asset". public class Asset { private UUID id; private String name; } And set an object of this class as a response. @GetMapping("/testSerialization") public Asset testSerialization() { return new Asset() } This controller works successfully. But when the same controller uses Geometry Types the request fails, import com.vividsolutions.jts.geom.Point; // Does not work @GetMapping("/testSerialization") public Point testSerialization() { GeometryFactory

How to handle object references in JSON document with Newtonsoft Json.NET?

丶灬走出姿态 提交于 2021-01-28 11:39:47
问题 I have a json dataset that comes with standard data fields and reference fields. It looks something like this: [ { "id":1, "name":"Book", "description":"Something you can read" }, { "id":2, "name":"newspaper", "description": { "ref":"0.description" } } ] This is my data model: public class PhysicalObject { [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.Default)] public int id; [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default)] public

Why Jackson JSON mapping exception when Serializing/Deserializing Geometry type

大城市里の小女人 提交于 2021-01-28 11:39:14
问题 When I create a User defined class "Asset". public class Asset { private UUID id; private String name; } And set an object of this class as a response. @GetMapping("/testSerialization") public Asset testSerialization() { return new Asset() } This controller works successfully. But when the same controller uses Geometry Types the request fails, import com.vividsolutions.jts.geom.Point; // Does not work @GetMapping("/testSerialization") public Point testSerialization() { GeometryFactory

How correctly use Gson to deserialize an object of generic type through a static utility method?

与世无争的帅哥 提交于 2021-01-28 08:57:29
问题 I've seen a number of other similar looking questions, but I think there's a level of abstraction on top of those that makes the difference. Namely, I have a utility class with a static generic wrapper method to deserialize an object of generic type (unknown at build time): public final class Utils { public static final Gson sGson = new Gson(); public static synchronized <T> T fromJson(String doc) { return sGson.fromJson(doc, new TypeToken<T>(){}.getType()); } } A simple class to test it on:

Serializable class cannot be deserialized

假装没事ソ 提交于 2021-01-28 07:27:14
问题 I have a graph i want to store in my DB and retrieve it in another package. My graph signature is: public class ModuleToModuleDependencyGraph extends DependencyGraph<ModuleNode, ModuleToModuleDependency> implements Serializable Signature of classes it extends and use : public class DependencyGraph<V extends Node, E extends DependencyEdge<? extends DependencyData>> extends DefaultDirectedGraph<V, E> implements IDependencyGraph<V, E>, Serializable public class ModuleNode extends Node implements

Hazelcast with global serializer (Kryo) - There is no suitable de-serializer for type

拈花ヽ惹草 提交于 2021-01-28 06:12:10
问题 I’m using Hazelcast 3.9 to cluster user sessions. To serialize the session objects, I created a global serializer implemented with Kryo (or more precisely KryoReflectionFactorySupport that allow to serialize objects without default constructor). public class GlobalKryoSerializer implements StreamSerializer<Object> { //use ThreadLocal because Kryo is not thread safe private static final InheritableThreadLocal <Kryo> kryoThreadLocal = new InheritableThreadLocal <Kryo>() { @Override protected

How to deserialize null type JSON fields with Jackson

不打扰是莪最后的温柔 提交于 2021-01-27 17:23:54
问题 I'm developing a PATCH API. If the fields are sent as JSON null value I need to save them as null . However I can't distinguish if they're sent as null or never sent. { "max_amount": null } Double maxAmount; I have Double , Integer , Date etc. fields. I can deserialize them to Double.NAN , Integer.MIN_VALUE when they're really sent as null to understand if they're sent as null . But Deserializers don't work when the field is null . Of course it's an option to send "-1" or an impossible value