Aspose.word - java - Custom method - object to string

JSON:

{ "data": { "formId": "118b3767-9c3b-4b1e-970b-bf5b940d4f7d", "userInput": { "otherA": "super manA", "industry": [ "K. Other Occupations" ], "educationLevel": [ "C. Tertiary or Above" ] } } }

Word
<<[TestFunc.test(data.userInput)]>>

Java program

ReportingEngine.getKnownTypes().add(TestFunc.class);
ReportingEngine.setOptions(ReportBuildOptions.ALLOW_MISSING_MEMBERS);
ReportingEngine.setUseReflectionOptimization(false);

public class TestFunc{
    public static void test(Object arr)
    {
        ObjectMapper mapper = new ObjectMapper();
        SimpleModule module = new SimpleModule();
        module.addSerializer(DBNull.class, new DBNullSerializer());
        mapper.registerModule(module);
        // Convert the input object to a JSON string
        String jsonString = mapper.writeValueAsString(arr);
        System.out.println("jsonString ="+jsonString );
    }
}

The printed output is:
Print.zip (487 字节)

The following was lost:
‌"industry"‌:[“K. Other Occupations”], ‌"educationLevel"‌:[“C. Tertiary or Above”]

@zhenglifan

The explanation has been provided in this comment.

1 Like