I am trying to call an API in my Dropwizard application, the API returns the following class
@Getter
@NoArgsConstructor
@AllArgsConstructor
@ToString
@EqualsAndHashCode
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "Error")
public class ErrorResponse {
@NonNull
@XmlAttribute(name = "msg")
private String msg;
@XmlAttribute(name = "display")
protected String display;
@XmlAttribute(name = "action")
private String action;
@NotNull
@XmlAttribute(name = "type")
private String type;
@XmlAttribute(name = "code")
private String code;
}
return javax.ws.rs.core.Response.status(status).entity(ErrorResponse).header(CONTENT_TYPE, APPLICATION_XML).build();
when I ran the application from IntelliJ, I got this response:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Error msg="some message" display="true" action="RETRY" type="FATAL" code="error"/>
when I ran it using the jar, I got this:
<ErrorResponse>
<msg>some message</msg>
<display>true</display>
<action>RETRY</action>
<type>FATAL</type>
<code>error</code>
</ErrorResponse>
I am using dropwizard 2.0.24
CodePudding user response:
Don't package your jar plain, use the maven-shade-plugin, that will include the dependencies in the jar, or, add these dependencies to your Classpath.
CodePudding user response:
- after deleting .m2 I got same response from IntelliJ and from the Jar.
- for some reason Dropwizard 2.0.24 was ignoring my JAXB annotations, I fixed it by changing the version to 2.0.0.
thanks for your comments, much appreciated