Hi,
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:
[[3,1,2,-1,"2021-09-20T08:55:31Z[UTC]",null],[4,1,2,-1,"2021-09-20T08:58:15Z[UTC]",null]]
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
@JsonbDateFormat("dd.MM.yyyy")
@JsonbProperty("dateAdd")
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;
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
@Provider
public class JSONConfigurator implements ContextResolver
{
@Override
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().
withConfig(config).
build();
}
}
Then I tried to add custom config to my application:
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
/**
* Configures JAX-RS for the application.
* @author Juneau
*/
@ApplicationPath("resources")
public class JAXRSConfiguration extends Application
{
@Override
public Set<Class<?>> getClasses()
{
Set<Class<?>> resources = new HashSet<Class<?>>();
resources.add(JSONConfigurator.class);
// resources.addAll(super.getClasses());
//// addRestResourceClasses(resources);
// resources.add(JSONConfigurator.class);
return resources;
}
}
Application just stopped working, without any error in server logs....