Please, help to customize web service JSON output format

Skip to first unread message

Сергей Хилков

Sep 29, 2021, 1:51:49 AM9/29/21
to Payara Forum
I have been trying to change JSON output of my web service, 
but all JSON annotations,  JSON configurators are not working.
The result output of sending list of objects from two instances looks like this:


It even doesnt contain field names( I have not found somebody had the same problem..)!
I tried to change at least date output format. I declare field with following annotations
No results! 

I have tried to create custom JSONB config. I created class

import javax.json.bind.Jsonb;
import javax.json.bind.JsonbBuilder;
import javax.json.bind.JsonbConfig;
import javax.json.bind.config.PropertyNamingStrategy;

public class JSONConfigurator implements ContextResolver

    public Jsonb getContext(Class type)
JsonbConfig config = new JsonbConfig().withDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", null).withPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE);;
return JsonbBuilder.newBuilder().

Then I tried to add custom config to my application:
import java.util.HashSet;
import java.util.Set;

 * Configures JAX-RS for the application.
 * @author Juneau
public class JAXRSConfiguration extends Application 
    public Set<Class<?>> getClasses() 
        Set<Class<?>> resources = new HashSet<Class<?>>();
// resources.addAll(super.getClasses());
////        addRestResourceClasses(resources);
//        resources.add(JSONConfigurator.class);
        return resources;

Application just stopped working, without any error in server logs....

Sergey K

Sep 29, 2021, 4:15:48 AM9/29/21
to Payara Forum
Update: I found that JSON without names is produced only for JPA objects...  How can I configure it??

среда, 29 сентября 2021 г. в 12:51:49 UTC+7, Sergey K:

Sergey K

Sep 29, 2021, 4:38:57 AM9/29/21
to Payara Forum
Annotations like @JsonbProperty("id")  also don't work with JPA objects.. 

среда, 29 сентября 2021 г. в 15:15:48 UTC+7, Sergey K:

Eduard Drenth

Sep 29, 2021, 6:12:56 AM9/29/21
to Sergey K, Payara Forum
You may consider using a construct like below (snippets...), though I think @JsonProperty should work if your annotated jpa objects didn't get transformed during processing.

private static final JsonbConfig jc = new JsonbConfig()

private static final JsonGeneratorFactory FACTORY = Json.createGeneratorFactory(jc.getAsMap());

private static final JsonBuilderFactory BUILDER_FACTORY = Json.createBuilderFactory(jc.getAsMap());

try (JsonGenerator generator = FACTORY.createGenerator(outputStream);) {
JsonObjectBuilder objectBuilder = BUILDER_FACTORY.createObjectBuilder();
params, 0, -1, outClass)
o -> generator.write(, o))

public interface JsonMapper<T> {
String LEMMA = "lemma";
String POS = "pos";
JsonMapper<Synonym> synonymJsonMapper = new JsonMapper<Synonym>() {
public JsonObject map(JsonObjectBuilder builder, Synonym s) {
return builder
.add(LEMMA, s.getLemma().getForm())
.add(POS, s.getLemma().getPos())
.add("synonym", s.getForm())
.add("meaning", s.getMeaning())
You received this message because you are subscribed to the Google Groups "Payara Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web, visit

Sergey K

Sep 30, 2021, 6:45:40 AM9/30/21
to Payara Forum
Thank you,  Eduard!
A problem was in a way I fetched objects... Query used to return just list of Objects... I changed that and problem was solved.

среда, 29 сентября 2021 г. в 17:12:56 UTC+7, Eduard Drenth:
Reply all
Reply to author
0 new messages