0

Is it possible to assign the jsog's @id value to an member variable in a POJO class?

For example I have a json:

"user": {
   "@id": "1",
   "name": "John Doe"
}

And Java class

@JsonIdentityInfo(generator=JSOGGenerator.class)
public class User {

   private String id; // this is null

   private String name;

   // getters and setters ...
}

I tried @JsonProperty("@id") but it my id still is null. Does anyone have an experience with this? I don't want to add another id field into my JSON as it makes it ugly.

Thank you in advance.

thehayro
  • 1,516
  • 2
  • 16
  • 28

1 Answers1

0

The identifier "@id" is not a valid Java property since it begins the '@' character. This is a nice feature since it won't conflict with any properties you have on your object.

I'm not sure how you transform that property into a Java property but you probably don't want to. The @id is purely for serialization/deserialization of the object graph; the @id value may change with each serialization if the object graph has changed.

You can't use the @id as an identifier of a object in a meaningful way outside of the serialization. You probably want a real ID that doesn't change based on serialization.

Scott Boring
  • 2,601
  • 1
  • 25
  • 31