No serializer found for class com.atlassian.jira.issue.security.IssueSecurityLevelImpl error

I am creating a Jira software server plugin for v7.13.0. I am creating an API to get all the issue security levels of a user.

my code is not working and is giving the following error:

2022-10-27 16:00:35,623 http-nio-8080-exec-13 ERROR      [o.a.c.c.C.[.[localhost].[/].[default]] Servlet.service() for servlet [default] in context with path [] threw exception

org.codehaus.jackson.map.JsonMappingException: No serializer found for class com.atlassian.jira.issue.security.IssueSecurityLevelImpl and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: java.util.HashSet[0])

Can anyone please help me in fixing this issue?

The class has properties that cannot be converted to string. You will have to construct your response by calling its methods and forming a string.

1 Like

Use DTO pattern to form serializable object for your response.

1 Like

Thank you so much for the reply. Is there any example code to implement the DTO pattern? Actually, I’m pretty new to java development.

Hi @DishantSharma

you can use lazy implementation like this:

        List<Map<String, Object>> response = new ArrayList<>();

        for(IssueSecurityLevel issueSecurityLevel : securityLevelsOfUser){
            Map<String, Object> temp = new HashMap<>();
            temp.put("id", securityLevelsOfUser.getId());
            temp.put("name", securityLevelsOfUser.getName());
            temp.put("description", securityLevelsOfUser.getDescription());
            temp.put("schemeId", securityLevelsOfUser.getSchemeId());
            response.add(temp);
        }

        return Response.ok(response).build();

Cheers
Adam

1 Like

Baeldung article contains examples. Anyway, google it, it’s a very common pattern.
Implementation by @adam.labus is nice and simple, but i think not very scalable, for example if you would like to extend your response with nested objects.

1 Like

thank you so much @adam.labus. I tried the code and it worked perfectly! Thanks for the help

@AlexeyDorofeyev thanks for the reply. yeah, you’re right. But, I think my requirement is for a smaller data set the solution by @adam.labus will work in my case. But, I have also created a DTO pattern for the same also which I will use in another plugin. Thank you so much for the help everyone!