Abstract Configurations with Yaml

559 views
Skip to first unread message

Cemo

unread,
Jul 24, 2013, 9:30:02 AM7/24/13
to dropwiz...@googlegroups.com
Hi,

I would like to choose dynamically PhotoConfiguration based on a given yml configuration file.

Example:

public interface PhotoConfiguration {}

public class FSPhotoConfiguration implements PhotoConfiguration{/* implementation */}

public class S3PhotoConfiguration implements PhotoConfiguration{/* implementation */}

And configuration

public class SampleConfiguration extends Configuration {

   @Valid
   @NotNull
   @JsonProperty
   private PhotoConfiguration photo;

   public PhotoConfiguration getPhoto() {
      return photo;
   }
}


My yml file:

photo: 
    key: yyy
    value: xxxx

I have checked this example [1] and tried

photo:  !!example.S3PhotoConfiguration
    key: yyy
    value: xxxx


Am I missing something? 




Thanks

Jochen Schalanda

unread,
Jul 24, 2013, 11:42:27 AM7/24/13
to dropwiz...@googlegroups.com
Hi,

On 24.07.2013 15:30, Cemo wrote:
> I would like to choose dynamically PhotoConfiguration based on a given
> yml configuration file.
> [...]
> Am I missing something?

Which errors do you encounter when running your example?


Regards,
Jochen

Cemo

unread,
Jul 24, 2013, 1:41:52 PM7/24/13
to dropwiz...@googlegroups.com

On 24 July 2013 18:42, Jochen Schalanda <joc...@schalanda.name> wrote:

Which errors do you encounter when running your example?

This is the exception I am having for both cases. 

Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of xxx.PhotoConfiguration, 
problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information
 at [Source: N/A; line: -1, column: -1] (through reference chain: xxx.MainConfiguration["photo"])
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:164)
at com.fasterxml.jackson.databind.DeserializationContext.instantiationException(DeserializationContext.java:600)
at com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserialize(AbstractDeserializer.java:114)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:464)
at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:107)
at com.fasterxml.jackson.module.afterburner.deser.SuperSonicBeanDeserializer.deserializeFromObject(SuperSonicBeanDeserializer.java:209)
at com.fasterxml.jackson.databind.deser.Bea

Tatu Saloranta

unread,
Jul 24, 2013, 1:59:00 PM7/24/13
to dropwiz...@googlegroups.com
Jackson YAML module does not have support for YAML-specific type id handling (same is true for Object Ids, FWIW).
It would be great to get that support added; so you may want to file an RFE at:

https://github.com/FasterXML/jackson-dataformat-yaml/issues

perhaps with sample object/yaml file included above?

-+ Tatu +-



--
You received this message because you are subscribed to the Google Groups "dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-us...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Tatu Saloranta

unread,
Jul 24, 2013, 2:00:19 PM7/24/13
to dropwiz...@googlegroups.com
Oh. Also -- it should be possible to use Jackson's JSON-style Type Id to work around the problem. Easiest way to see what that means is actually adding @JsonTypeInfo in abstract class, construct an instance, serialize this (either as JSON or YAML), and see how property is added.

This is cumbersome but should work as of now.

Hope this helps,

-+ Tatu +-

Cemo

unread,
Jul 24, 2013, 3:57:08 PM7/24/13
to dropwiz...@googlegroups.com

On 24 July 2013 20:59, Tatu Saloranta <tsalo...@gmail.com> wrote:
Jackson YAML module does not have support for YAML-specific type id handling (same is true for Object Ids, FWIW).
It would be great to get that support added; so you may want to file an RFE at:

https://github.com/FasterXML/jackson-dataformat-yaml/issues

perhaps with sample object/yaml file included above?


Hi Tatu,

Thanks for the prompt response as always. I have filed an issue[1] and created a sample application[2] to raise same exception.

Thanks



Tatu Saloranta

unread,
Jul 24, 2013, 6:57:15 PM7/24/13
to dropwiz...@googlegroups.com
Thanks!

-+ Tatu +-


Reply all
Reply to author
Forward
0 new messages