Use of anchors in Dropwizard Configuration

443 views
Skip to first unread message

sjames...@gmail.com

unread,
Jun 26, 2014, 11:36:07 AM6/26/14
to dropwiz...@googlegroups.com
Hi

I would like to use anchors in my Dropwizard configuration file.
For example:


schedules
:
 
ScheduleA: &id001
    commands:
      - type: event
        name: Event1
      - type: delay
        period: 1m

# Detail omitted...

nodes
:
 
- address: 127.0.0.1
   schedule
: *id001

However, the parser objects:

emu.yml has an error:

 
* Failed to parse configuration at: nodes.schedule; Can not instantiate value of type java.lang.String from String value; no single-String constructor/factory method (through reference chain: com.company.EmulatorConfiguration["nodes"]->com.company.NodeConfiguration["schedule"])


Is this is an issue with the version of jackson that Dropwizard is using?

Thanks.

Simon

Justin Miller

unread,
Jun 26, 2014, 11:40:33 AM6/26/14
to dropwiz...@googlegroups.com
Have you tried wrapping *id001 with ""?
> --
> 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/d/optout.

sjames...@gmail.com

unread,
Jun 26, 2014, 11:47:18 AM6/26/14
to dropwiz...@googlegroups.com
I had not tried that, but I have now and I get the same error.

Justin Miller

unread,
Jun 26, 2014, 11:51:56 AM6/26/14
to dropwiz...@googlegroups.com
Can you post the configuration code?

sjames...@gmail.com

unread,
Jun 26, 2014, 12:10:04 PM6/26/14
to dropwiz...@googlegroups.com

I’m assuming you mean the Java code.

Somewhat simplified, I have:

public class EmulatorConfiguration extends Configuration {

   
@NotEmpty
   
@JsonProperty("nodes")
   
private List<NodeConfiguration> nodes;

   
@JsonProperty
   
private Map<String, Schedule> schedules;

}

public class Schedule {

   
@NotEmpty
   
@JsonProperty
   
private List<ScriptCommand> commands;
}

public class NodeConfiguration {

   
@NotEmpty
   
private String address;

   
@JsonProperty
   
private Schedule schedule;

}

sjames...@gmail.com

unread,
Jun 26, 2014, 12:22:43 PM6/26/14
to dropwiz...@googlegroups.com
I should have added that I have tried this with versions 0.7.0 and 0.7.1 of Dropwizard.

Tatu Saloranta

unread,
Jul 9, 2014, 5:00:41 PM7/9/14
to dropwiz...@googlegroups.com
First: to have any support for YAML anchors and references, Jackson 2.4 must be used; this version supports used of YAML's native object and type id constructs.

Unfortunately this is not quite enough to yet support anchors, since Jackson databind also needs to be aware of possible Object Ids. This means that value types in question need to enable object id support with @JsonIdentityInfo.

I have not tried using this yet, but theoretically it should work.
So in this example, @JsonIdentityInfo should be added to type Schedule.

I would be interested in knowing if this works, or if not, what error is being given.
One open question is what happens to instances without anchor.

-+ Tatu +-



Reply all
Reply to author
Forward
0 new messages