RE: how to get json from structures liferay 7.4

Jamie Sammons, 4 Jaren geleden aangepast. New Member Bericht: 1 Aanmelddatum: 24-9-21 Recente berichten

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, 2 Jaren geleden aangepast. Junior Member Berichten: 79 Aanmelddatum: 9-12-11 Recente berichten

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);
        }
    }