moxy

MessageBodyWriter not found for media type=application/json

丶灬走出姿态 提交于 2019-12-02 00:49:27
I'm making a small RESTful service using Jetty. Using Maven as the build tool. When I try to call a GET method that tries to access a JSON representation of an object, I get an "MessageBodyWriter" error. The method in question is as follows, @Path("/gtfs-rt-feed") public class GtfsRtFeed { @GET @Produces(MediaType.APPLICATION_JSON) public Response getGtfsRtFeed(){ GtfsRtFeedModel feedInfo = new GtfsRtFeedModel(); feedInfo.setStartTime(121334); feedInfo.setGtfsId(1); feedInfo.setGtfsUrl("http://www.google.com"); Gson gson = new Gson(); return Response.ok(feedInfo).build(); } ... The

With MOXy and XPath, is it possible to unmarshal a list of attributes?

ⅰ亾dé卋堺 提交于 2019-12-02 00:21:01
问题 Edit: here's how I'm loading the XML document, as I used it in Blaise's answer. I'm loading it like this because I want to work with a node, not the whole doc. Even using the whole document I'm still having trouble when loading in this manner. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setNamespaceAware(false); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse("[path to doc]/input.xml");

JAXB ignoring xml tag attribute

主宰稳场 提交于 2019-12-01 23:09:14
I read xml files with JAXB. I have the following structure <A> <B value="some string" /> </A> I have the following model @XmlRootElement class A{ @XmlElement(name = "B", required = true) @XmlPath("B/@value") String b; } I read the B tags value attribute in my b Instance variable. But in some XML files i have in the B tag following Structure <#B/> While JAXB unmarshall the files i become exception that the format is not correct. javax.xml.stream.XMLStreamException: ParseError at [row,col]:[19,4] You should just have the following without the @XmlElement annotation: @XmlRootElement class A{

With MOXy and XPath, is it possible to unmarshal a list of attributes?

荒凉一梦 提交于 2019-12-01 21:42:14
Edit: here's how I'm loading the XML document, as I used it in Blaise's answer. I'm loading it like this because I want to work with a node, not the whole doc. Even using the whole document I'm still having trouble when loading in this manner. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setNamespaceAware(false); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse("[path to doc]/input.xml"); TestClass testClass = (TestClass) unmarshaller.unmarshal(doc); I've got XML that looks like this: <test>

NPE when using MOXy's meta data with a class that implements java.util.Map

早过忘川 提交于 2019-12-01 21:29:57
问题 The situation I'm using EclipseLink's MOXy and I'm trying to use the external OX mapping XML with classes that implement the Map interface. However, every time I try create a JAXBContext, I get the following NPE: Caused by: javax.xml.bind.JAXBException - with linked exception: [java.lang.NullPointerException] at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:832) at org.eclipse.persistence.jaxb.JAXBContext.<init>(JAXBContext.java:143) at org

NPE when using MOXy's meta data with a class that implements java.util.Map

冷暖自知 提交于 2019-12-01 19:31:10
The situation I'm using EclipseLink's MOXy and I'm trying to use the external OX mapping XML with classes that implement the Map interface. However, every time I try create a JAXBContext, I get the following NPE: Caused by: javax.xml.bind.JAXBException - with linked exception: [java.lang.NullPointerException] at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:832) at org.eclipse.persistence.jaxb.JAXBContext.<init>(JAXBContext.java:143) at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:142) at org.eclipse

How to bind a xml element into an object member variable?

泄露秘密 提交于 2019-12-01 06:44:35
I'm trying to unmarshal an xml to an object using moxy.Below is the sample of the xml. <root> <name> <firstname>value</firstname> </name> <address>value of address</address> </root> And below is the class I'm trying to map. import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import org.eclipse.persistence.oxm.annotations.XmlPath; @XmlRootElement(name="root") @XmlAccessorType(XmlAccessType.FIELD) public class Response { @XmlPath("name/firstname/text()")

JAXB inheritance in MOXY

无人久伴 提交于 2019-12-01 06:21:31
I have two classes: package a; class A { private <type> fieldOfClassA; // getters, and setters } package b; class B extends A{ private <type> fieldOfClassB; // getters, and setters } I want to marshal class B to an xml element and add the attribute fieldOfClassB, and fieldOfClassA from class A but it prints the following warning message during marshalling: Ignoring attribute [fieldOfClassA] on class [b.B] as no Property was generated for it. Note that the two class is from two different packages and I can't change this object model. Thank you in advance! EDIT: I am using external binding files

NPE Thrown Marshalling Entity in JAX-RS

自闭症网瘾萝莉.ら 提交于 2019-12-01 05:51:23
I have a JAX-RS webservice that makes use of JPA entity classes. I have a resource class like this: @Path("/entity") public class MyEntityResource { @GET @Produces(MediaType.APPLICATION_XML) @Path("/{entity}") public MyEntity getMyEntity(@PathParam("entity") String entity) { log.debug("Entering getMyEntity with param: " + entity); MyEntity entityObject = genericService.find(MyEntity.class, entity); if (entityObject == null) { log.debug("Entity not found."); throw new WebApplicationException(Response.Status.NOT_FOUND); } log.debug("Exiting getMyEntity"); return entityObject; } } When I run the

Using an adapter to marshal a class to a root element with MOXy or any other JAXB implementation

狂风中的少年 提交于 2019-12-01 05:34:16
问题 I have a class which extends the CompositeConfiguration class from Apache Commons Configuration. I am trying to marshal it to XML using MOXy. I have created an XML adapter that converts the configuration to a list of simple name/value objects. I have tried using a number of variations on what I have below but am still stymied. I can see my adapter class being loaded and instantiated when I create the JAXB context but it is never called when I marshal the configuration object. Looking at the