Questions tagged [deserialization]

Deserialization is the process by which an object is recreated from its serialized state.

7954 questions
64
votes
4 answers

Java serialization - java.io.InvalidClassException local class incompatible

I've got a public class, which implements Serializable, that is extended by multiple other classes. Only those subclasses were ever serialized before - never the super class. The super class had defined a serialVersionUID. I'm not sure if it…
Dale
  • 3,527
  • 6
  • 24
  • 22
63
votes
1 answer

What are @JsonTypeInfo and @JsonSubTypes used for in jackson

What are the @JsonTypeInfo and @JsonSubTypes annotations used for in Jackson? public class Lion extends Animal { private String name; @JsonCreator public Lion(@JsonProperty("name") String name) { this.name = name; } public String getName() { …
Harshit
  • 1,174
  • 1
  • 9
  • 24
63
votes
10 answers

java.io.InvalidClassException: local class incompatible:

I created client and server and then added a class in client side for serializing purposes, then simply just went to the folder of the client in my hard drive and copy paste it to the server correponding location, both classname.class and…
lonesome
  • 2,503
  • 6
  • 35
  • 61
62
votes
5 answers

What's the Jackson deserialization equivalent of @JsonUnwrapped?

Say I have the following class: public class Parent { public int age; @JsonUnwrapped public Name name; } Producing JSON: { "age" : 18, "first" : "Joey", "last" : "Sixpack" } How do I deserialize this back into the Parent class? I could…
Shaun
  • 2,490
  • 6
  • 30
  • 39
60
votes
8 answers

Deserializing polymorphic types with Jackson based on the presence of a unique property

If I have a class structure like so: public abstract class Parent { private Long id; ... } public class SubClassA extends Parent { private String stringA; private Integer intA; ... } public class SubClassB extends Parent { …
Sam Berry
  • 7,394
  • 6
  • 40
  • 58
58
votes
8 answers

How to handle a NumberFormatException with Gson in deserialization a JSON response

I'm reading a JSON response with Gson, which returns somtimes a NumberFormatException because an expected int value is set to an empty string. Now I'm wondering what's the best way to handle this kind of exception. If the value is an empty string,…
Soundlink
  • 3,915
  • 2
  • 28
  • 36
58
votes
3 answers

Polymorphism in jackson annotations: @JsonTypeInfo usage

I would like to know if @JsonTypeInfo annotation can be used for interfaces. I have set of classes which should be serialized and deserialized. Here is what I'm trying to do. I have two implementation classes Sub1, Sub2 implementing MyInt. Some of…
Chris
  • 5,584
  • 9
  • 40
  • 58
57
votes
3 answers

How do I write a custom JSON deserializer for Gson?

I have a Java class, User: public class User { int id; String name; Timestamp updateDate; } And I receive a JSON list containing user objects from a…
Jonas
  • 121,568
  • 97
  • 310
  • 388
57
votes
3 answers

How to load a JSON file and convert it to an object of a specific type?

I have a type FooObject and I have a JSON file which was serialized from a FooObject instance. Now I want to use ConvertFrom-Json to load the JSON file to memory and covert the output of the command to a FooObject object, and then use the new object…
NonStatic
  • 951
  • 1
  • 8
  • 27
57
votes
4 answers

Serializing/deserializing with memory stream

I'm having an issue with serializing using memory stream. Here is my code: /// /// serializes the given object into memory stream /// /// the object to be serialized /// The serialized…
gng
  • 715
  • 1
  • 5
  • 13
56
votes
3 answers

Why my exception class needs to be serialized?

When you extend a class with class Exception ( for creating new exception) you get a warning to have a serialVersionUID. I know that serialVersionUID plays an important role while serialization and deserialization, but when my Exception needs to be…
amod
  • 4,190
  • 10
  • 49
  • 75
56
votes
5 answers

Cannot deserialize the current JSON array (e.g. [1,2,3]) into type

I have a class like this: public class MyStok { public int STId { get; set; } public int SM { get; set; } public string CA { get; set; } public string Br { get; set; } public string BNo { get; set; } public decimal Vat { get;…
sakir
  • 3,391
  • 8
  • 34
  • 50
55
votes
5 answers

How do I use JSON.NET to deserialize into nested/recursive Dictionary and List?

I need to deserialize a complex JSON blob into standard .NET containers for use in code that is not aware of JSON. It expects things to be in standard .NET types, specifically Dictionary or List where "object" can be…
dongryphon
  • 705
  • 1
  • 5
  • 8
54
votes
3 answers

Error Deserializing Xml to Object - xmlns='' was not expected

I am having real trouble trying to deserialize some XML and was hoping someone can offer some assistance. I have read a lot of similar posts but I am unable to resolve this. XML I am attempting to deserialize
ProNotion
  • 3,662
  • 3
  • 21
  • 30
54
votes
7 answers

Deserialize JSON into existing object (Java)

I'd like to know how one might get the Jackson JSON library to deserialize JSON into an existing object? I've tried to find how to to this; but it seems to only be able to take a Class and instantiate it itself. Or if not possible, I'd like to know…
Jonas N
  • 1,757
  • 2
  • 21
  • 41