Reputation: 465
I have a question in Hibernate annotations. I have an Entity, in that I have an column and I am using @JsonSerialize to converter the value to a different formate and using the @JsonProperty I am writing it to a different field in the output json:
@Transient
@Type(type = "org.hibernatespatial.GeometryUserType")
@Column(name = "the_geom", columnDefinition = "Geometry")
Geometry gml;
@JsonProperty("wkt")
@JsonSerialize(using = JsonGeometrySerializer.class)
public Geometry getGeom() {
return geom;
}
public void setGeom(Geometry geom) {
this.geom = geom;
}
Now I want to create a different property like @JsonProperty("gml") for the same geometry coming from the the_geom column and write it to a different field in the output json. Is there a way I can specify multiple values in the @JsonProperty? I tried creating another variable with getter/setters and use @Trancient but not sure how to send the the_geom value to that serializer. Please help.
I tried something like this and did not work:
@Transient
@Type(type = "org.hibernatespatial.GeometryUserType")
@Column(name = "the_geom", columnDefinition = "Geometry")
Geometry gml;
@JsonSerialize(using = JsonGeometrySerializer.class)
public Geometry getGml() {
return gml;
}
public void setGml(Geometry gml) {
this.gml = gml;
}
SO in the first case the Geometry should be converted to wkt and added to the json and in the second the geometry should be converted to the GML format and added to the gml. Can I have the same JsonSerializer class to do both or do I have to write a new one?
Upvotes: 1
Views: 1572
Reputation: 8154
Since you are attaching the @JsonSerializer to the method, whats stopping you from creating another getXXX method returning whatever you want, including the same value?
Upvotes: 2