holon-platform/holon-jaxrs

Creating Array using PropertyBox

vaithu opened this issue · 0 comments

How do I create an array using PropertyBox ?

Here is the code I tried to create.

ListPathProperty<String> QUEUE = ListPathProperty.create("queue",String.class);
		StringProperty NAME = StringProperty.create("name").parent(QUEUE);
		StringProperty TYPE = StringProperty.create("type").parent(QUEUE);

		PropertySet<?> PROPERTIES = PropertySet.of(QUEUE, NAME, TYPE);
		PropertyBox pb = PropertyBox.create(PROPERTIES);
		pb.setValue(NAME,"a");
		pb.setValue(TYPE,"local");
		Json json = Json.require();

		List<PropertyBox> boxes = new ArrayList<>();
		boxes.add(pb);

		pb = pb.cloneBox();
		pb.setValue(NAME,"b");
		pb.setValue(TYPE,"remote");

		boxes.add(pb);

		System.out.println(json.toJson(boxes).asString());

The output generated is

[{"queue":{"name":"a","type":"local"}},{"queue":{"name":"b","type":"remote"}}]

whereas I need them as

{"queue": [{"name":"a","type":"local"},{"name":"b","type":"remote"}]}