how to get json from structures liferay 7.4

Jamie Sammons, modified 4 Years ago. New Member Post: 1 Join Date: 9/24/21 Recent Posts

I have a question for you, i don't understand why in this newest version of liferay there is no section of "code for the structure" for get the json.
On liferay from 6.x to 7.3 there were this section. There are some settings to do for this ?

Thanks, 
Gianluca.

thumbnail
Charalampos Chrysikopoulos, modified 2 Years ago. Junior Member Posts: 79 Join Date: 12/9/11 Recent Posts

Hi Gianluca,

you could try using the following code:

        @Reference
    private com.liferay.dynamic.data.mapping.io.DDMFormSerializer ddmFormSerializer;

...


    private void getStructureJson(long groupId) {

        List<DDMStructure> structures = DDMStructureLocalServiceUtil.getStructures(groupId);
        for (DDMStructure structure : structures) {
            _log.info("STRUCTURE KEY:" + structure.getStructureKey());
            DDMFormSerializerSerializeRequest.Builder builder = DDMFormSerializerSerializeRequest.Builder.newBuilder(structure.getDDMForm());
            DDMFormSerializerSerializeResponse ddmFormSerializerSerializeResponse =  ddmFormSerializer.serialize(builder.build());
            String json = ddmFormSerializerSerializeResponse.getContent();
            _log.info("  JSON:" + json);
        }
    }