0

I am working on a web service to insert data into a sqd server, as I am new to this, I am doing small tests.

You have created a rest web service in netbeans, create a person entity, the only thing that the service does is receive an object in xml or json format and then store it in persistence. When I send an xml format like this:

<persona>
<idPersona>20</idPersona>
<nombre>Albert</nombre>
<trabajador>true</trabajador>
</persona>"

Works fine, but when I send the object in json format like this:

{
"idPersona":"20",
"nombre":"Bernard",
"trabajador":"true"
}

I get a 500 (Internal Server Error). I have been guiding a tutorial online, I followed all the steps, in the tutorial there are pictures and everything is perfect, but in my case it is not like that.

Did someone have the same problem? I hope you can help me. Thank you.

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
Julio Rafael
  • 11
  • 1
  • 6
  • 1
    You have to look at the server log to see what error caused the 500. The 500 is like the Check-Engine light, it tells you nothing other than that something failed. Also, do not post images of code. Copy/paste the actual code into your post. – Jim Garrison Feb 16 '17 at 23:45
  • You should add the necessary information quickly if you want to avoid downvotes for insufficient information. If necessary, delete your post and undelete it when you can add the server log stack trace. – Jim Garrison Feb 16 '17 at 23:47
  • @JimGarrison, Excuse my ignorance, but where would you see the record you're writing? – Julio Rafael Feb 16 '17 at 23:47
  • You should have access to the server log files. If your server runs on your system you'll have to look for them. The specific location will depend on the server (Tomcat, JBoss, etc) and how it was installed. If someone else manages the server you'll have to ask them. – Jim Garrison Feb 16 '17 at 23:48
  • I'm working locally with glassfish – Julio Rafael Feb 16 '17 at 23:49
  • In NetBeans go to the "Services" tab open "Servers", right-click on your Glassfish instance and click "View Domain Server Log".? – Julio Rafael Feb 16 '17 at 23:51
  • Maybe you can help me with this? – Julio Rafael Feb 16 '17 at 23:53
  • Advertencia: StandardWrapperValve[org.netbeans.rest.application.config.ApplicationConfig]: Servlet.service() for servlet org.netbeans.rest.application.config.ApplicationConfig threw exception java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.persistence.jaxb.BeanValidationHelper – Julio Rafael Feb 16 '17 at 23:54
  • at org.eclipse.persistence.jaxb.JAXBBeanValidator.isConstrainedObject(JAXBBeanValidator.java:257) at org.eclipse.persistence.jaxb.JAXBBeanValidator.shouldValidate(JAXBBeanValidator.java:208) at org.eclipse.persistence.jaxb.JAXBUnmarshaller.validateAndBuildJAXBElement(JAXBUnmarshaller.java:235) at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:339) at org.eclipse.persistence.jaxb.rs.MOXyJsonProvider.readFrom(MOXyJsonProvider.java:660) – Julio Rafael Feb 16 '17 at 23:54
  • at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.invokeReadFrom(ReaderInterceptorExecutor.java:256) at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:235) at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:155) – Julio Rafael Feb 16 '17 at 23:55
  • Don't post stack trace in comments. Please [edit] your post, and format as code (use the `{}` button) – Jim Garrison Feb 16 '17 at 23:58

1 Answers1

2

You treat your boolean like a string and persona is missing. But your json should look like this:

{
  "persona": {
    "idPersona": "20",
    "nombre": "Bernard",
    "trabajador": true
  }
}
n00bst3r
  • 637
  • 2
  • 9
  • 17