artiya4u / google-http-java-client

Automatically exported from code.google.com/p/google-http-java-client
0 stars 0 forks source link

@JsonPolymorphicTypeMap doesn't work with custom Key names #258

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Version of google-http-java-client (e.g. 1.15.0-rc)?

google-http-client-1.16.0-rc

Java environment (e.g. Java 6, Android 2.3, App Engine)?

Android KitKat

Describe the problem.

This works:
    @Key
    @JsonPolymorphicTypeMap(typeDefinitions = {
        @TypeDef(key = "TextSearchParameter", ref = TextSearchParameter.class),
        @TypeDef(key = "CurrentLocationSearchParameter", ref = CurrentLocationSearchParameter.class),
    })
    private String type = getClass().getSimpleName();

This doesn't work (exactly the same but with a custom value provided for the 
@Key annotation):
    @Key("CustomKey")
    @JsonPolymorphicTypeMap(typeDefinitions = {
        @TypeDef(key = "TextSearchParameter", ref = TextSearchParameter.class),
        @TypeDef(key = "CurrentLocationSearchParameter", ref = CurrentLocationSearchParameter.class),
    })
    private String type = getClass().getSimpleName();

When I try to parse using the second example, I get an IllegalArgumentException 
saying "No value specified for @JsonPolymorphicTypeMap field". It seems pretty 
clear that it's doing a lookup based on the field name rather than the field's 
@Key.

How would you expect it to be fixed?

Custom @Key values should be supported!

Original issue reported on code.google.com by chris.va...@laterooms.com on 2 Apr 2014 at 1:36