Expand my Community achievements bar.

SOLVED

Utility to convert AEM 6.4 multifield node into JSON format

Avatar

Level 2

Hi All,

Does AEM provide a utility to convert Coral 3 multi-field node structure into a JSON format?

We have a requirement where we need to migrate our Legacy Coral 2 multi-field component to new Coral 3 structure that stores the data in node structure.

We do not want to change logic for reading the dialog data and hence want to know if there is already any per-written utility, which AEM provides to do this conversion.

Please suggest if any.

Regards,

Shikha

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi,

Coral3 stores multi field in node structure.

You can simply access those nodes inside WCMUsePojo or Model and write a function which converts nodes data into JSON and return for further processing.

The idea is let AEM stores data in node structure but if you already have written your logic based on JSON, just put few lines of code to convert Node to JSON, if you are writing new logic then go ahead with node structure no need to convert.

Converting Node to JSOn at backend is super easy as compared to actual store values in json in node.



Arun Patidar

View solution in original post

5 Replies

Avatar

Correct answer by
Community Advisor

Hi,

Coral3 stores multi field in node structure.

You can simply access those nodes inside WCMUsePojo or Model and write a function which converts nodes data into JSON and return for further processing.

The idea is let AEM stores data in node structure but if you already have written your logic based on JSON, just put few lines of code to convert Node to JSON, if you are writing new logic then go ahead with node structure no need to convert.

Converting Node to JSOn at backend is super easy as compared to actual store values in json in node.



Arun Patidar

Avatar

Level 2

Hi,

I have almost similar problem. I have migrated coral 2 component to new coral 3. I want to convert existing multi-field Json data to nodes data.

Any help would be appreciated.

Thanks

Harpreet

Avatar

Level 7

You can achieve this using sling models very easily-

@Model(adaptables=Resource.class)

public class MyModel {

    @Inject

    private List<Resource> addresses;

}

Here addresses the node name under which the multi-field nodes are getting saved

+- addresses

    |

    +- address1

    |

    +- address2

Refer:

Apache Sling :: Sling Models

Avatar

Level 2

I am not sure if this is going to solve the problem. I want to convert the actual data.

The scenario is, I had a coral 2 component and there are multi-fields saved in Json format. Now as coral 2 component is upgraded to coral 3, the new multi-field values are getting saved as nodes. The upgraded component is fine as long as new multi-fields values are saved and displayed. The problem is with the previous multi-field data stored in Json. Can I covert those multi-field Json data to nodes so that upgraded component can work well with both new and old multi-fields?

If you have any other suggestion to deal with existing Json format multi-field with coral 3 component.

Thanks

Avatar

Community Advisor

The easiest way to handle existing JSON data for repopulating with coral3 type is converting json to nodes.

A script can search for all the multifield for a component type and create node structure from existing json.



Arun Patidar