I am trying to send an array of objects to a REST service. It says it doesn't know how to marshall and Array. I can get it to marshall out to json, but I can not get it to POST. Any tips?
Customer customer = new Customer();
customer.setCompanyName("Fancy Diddly");
// other setters
List<AMCRegistration> customers = new ArrayList<>();
customers.add(customer);
Marshaller marshaller;
marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON);
marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false);
marshaller.setProperty(MarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
//marshaller.setProperty(MarshallerProperties.JSON_, true);
marshaller.marshal(customers, System.out);
This is the marshall output.
[
{
"registered_state_abbr" : "CA",
"state_registration_number" : "789",
"registration_status" : "Active",
"operation_type_id" : 1,
"fed_regulated" : "Yes",
"ein" : "12-34",
"company_name" : "Fancy Diddly",
"phone_no" : "916-123-5432"
},
{
"registered_state_abbr" : "CA",
"state_registration_number" : "1337",
"registration_status" : "Active",
"operation_type_id" : 1,
"fed_regulated" : "Yes",
"ein" : "56-89",
"company_name" : "Bo Schmooh",
"phone_no" : "916-456-9876"
}
]
Yet, if I try to POST, it throws an exception
Client client = ClientBuilder.newClient();
HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("user", "pass");
client.register(feature);
WebTarget target = client.target("https://customer-service.foo.org/api/cust");
target = target.path("PostCUSTOMERS");
Response responseBean = target
.request(MediaType.APPLICATION_JSON_TYPE)
.post(Entity.entity(customers, MediaType.APPLICATION_JSON_TYPE), Response.class);
System.out.println(responseBean);
Here is the exception
Apr 12, 2021 5:19:45 PM org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo
SEVERE: MessageBodyWriter not found for media type=application/json, type=class java.util.ArrayList, genericType=class java.util.ArrayList.
Exception in thread "main" org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=application/json, type=class java.util.ArrayList, genericType=class java.util.ArrayList.