Closed GoogleCodeExporter closed 9 years ago
Original comment by yan...@google.com
on 10 Jan 2013 at 12:30
Some initial thoughts:
Should LineString be @Key List<List<BigDecimal>> coordinates or @Key
List<Point> coordinates?
How would you initialize a Polygon? Does Java have a simple initializer for
Lists of Lists of Lists?
Original comment by jmcg...@google.com
on 10 Jan 2013 at 4:47
James, I think those are good questions. But I hadn't intended for that to be
the purpose of this feature request. So if you don't mind let me narrow the
focus of this feature request to support for heterogeneous schemas, meaning
schemas for whom there is a choice of which schema to use based on the value of
a single top-level property. GeoJson is a good example of that, but in our
implementation we will suppose that other use cases exist, so we will implement
it to work for the most general use cases.
I think it may be worthwhile to look at other JSON <-> Java mapping libraries
like Jackson or GSON and see how they implement this.
Original comment by yan...@google.com
on 12 Jan 2013 at 3:12
Original comment by yan...@google.com
on 18 Jan 2013 at 3:09
For reference, GSON allows you to register a JSON deserializer or a type
adapter:
http://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/J
sonDeserializer.html
http://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/T
ypeAdapter.html
Jackson has an even more sophisticated mechanism with even a built-in concept
of registering different types based on the value of a property:
http://programmerbruce.blogspot.com/2011/05/deserialize-json-with-jackson-into.h
tml
Sample code snippet copied from the above blog:
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
property = "type")
@JsonSubTypes({
@Type(value = Cat.class, name = "cat"),
@Type(value = Dog.class, name = "dog") })
abstract class Animal
{
public String name;
}
class Dog extends Animal
{
public String breed;
public String leashColor;
}
class Cat extends Animal
{
public String favoriteToy;
}
I like this annotation based approach, and that seems to me the most appealing
approach for use case at hand. We may have to provide greater customization in
the future, but for now this seems like the simplest solution.
Original comment by yan...@google.com
on 19 Jan 2013 at 2:25
Original comment by yan...@google.com
on 24 Jan 2013 at 1:49
Original comment by yan...@google.com
on 5 Feb 2013 at 4:48
Something I would like to see handled is the unknown case. Supporting a
'default' case if the JSON type is not known to the client.
Original comment by yincrash
on 4 Mar 2013 at 7:28
Original comment by yan...@google.com
on 25 Mar 2013 at 7:32
https://codereview.appspot.com/9618044/
Original comment by ngmic...@google.com
on 28 May 2013 at 3:43
Hi Michael,
A "default" case was not part of the initial set of requirements for the
feature, but it certainly could be useful. If this is something you would like
to see and have a use-case for, please feel free to open a new feature request,
and include as much detail as possible.
One way you could use the features implemented is to make your type field a
value type, such as an int. Currently, if the type field is null, an exception
is thrown. However, if the type field is an unspecified int, it will have a
value of 0. You could then define 0 to map to whatever default type you want.
Of course, this is not a perfect design, as it wouldn't work if a value of "0"
actually had meaning to your data.
Original comment by ngmic...@google.com
on 28 Jun 2013 at 12:10
Original issue reported on code.google.com by
yan...@google.com
on 13 Dec 2012 at 2:11