Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Getting properties from node and storing in String[]

ks_hitijingole
Level 2
Level 2

Hi,

 

I have a component with multifiled (testAppIDs). The multifield data gets stored in form of nodes after Coral 3 migration (item0,item1 etc.). 

ks_hitijingole_0-1623251491719.png

 

Earlier before Coral 3 Migration Model class had a logic to use the JSON array. I want the model class to use the same logic as the impact might be huge. So now after Coral 3 migration, as I cannot pass testAppIDs using @ValueMapValue , I am trying to create the same String[] by iterating through child node of testAppIDs. 

ks_hitijingole_1-1623251856057.png

Can you help me understand how can I fetch property and value data from the item nodes and put it in testAppIds String []. Sample Data Expected to be stored in testAppIds ->  [{"tapID":"TAP_10050"}, {"tapID":"TAP_10049"}, {"tapID":"TAP_10050"}]

1 Accepted Solution
davidjgonzalezzzz
Correct answer by
Level 5
Level 5
// using gson JsonObject

List<String> tapIds = new ArrayList<String>();

for(Resource item : items.getChildren()) {
     JsonObject itemObject = new JsonObject();
     itemObject.addProperty("tapID", item.getValueMap().get("tapID", String.class));
     tapIds.add(itemObject.toString());
}

return tapIds.toArray(new String[tapIds.size()]);

Should be able to do something like that? i wrote that in the comment field itself, so there might be some syntax issues ... but should give you the gist. You can do it more concisely in a stream, but that's just style.

View solution in original post

0 Replies
davidjgonzalezzzz
Correct answer by
Level 5
Level 5
// using gson JsonObject

List<String> tapIds = new ArrayList<String>();

for(Resource item : items.getChildren()) {
     JsonObject itemObject = new JsonObject();
     itemObject.addProperty("tapID", item.getValueMap().get("tapID", String.class));
     tapIds.add(itemObject.toString());
}

return tapIds.toArray(new String[tapIds.size()]);

Should be able to do something like that? i wrote that in the comment field itself, so there might be some syntax issues ... but should give you the gist. You can do it more concisely in a stream, but that's just style.

View solution in original post