Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Trying to send array of objects on json
Trying to send array of objects on json [message #1840348] Tue, 13 April 2021 00:34 Go to next message
Brian Lavender is currently offline Brian LavenderFriend
Messages: 20
Registered: July 2009
Junior Member
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.
Re: Trying to send array of objects on json [message #1840352 is a reply to message #1840348] Tue, 13 April 2021 05:52 Go to previous message
Brian Lavender is currently offline Brian LavenderFriend
Messages: 20
Registered: July 2009
Junior Member
I am thinking that I need to register the moxy provider such as on this example? I now of course wonder if my marshalling is actually using the Moxy?
Previous Topic:Create an array of objects when marshalled to json
Next Topic:Documentation for refresh.cascade query hint
Goto Forum:
  


Current Time: Sun Jun 20 08:14:11 GMT 2021

Powered by FUDForum. Page generated in 0.01696 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top