moxy

JSON to object in Java

你。 提交于 2019-12-12 05:59:51
问题 I have the following JSON: { "book":{ "isbn" : "12356789", "title" : "Algorithm", "author" : [ "Cormen", "Rivest", "Stein" ], "price" : 45.78 } } I need to convert this JSON string to a Book class. I don't want to set it property by property. Also, I don't want to use Gson. I want to do something as: Book book=jsonReader.readObject().toClass(Book.class); How can I do it with javax.json.Json or Moxy ? 回答1: I would recommend NOT using anything other than Jackson to process json. A Jackson based

JAXB marshall List<String> JSON?

天大地大妈咪最大 提交于 2019-12-12 04:44:16
问题 I am using JAXB (MoXY) for marshalling/unmarshalling my data in XML and JSON both. I have a List<String> wrapped in a class which I want send over the wire: @XmlRootElement(name = "carList") public class CarsList { @XmlValue protected List<String> cars; public List<String> getCars() { if (cars == null) { cars = new ArrayList<String>(); } return cars; } public void addCar(String carId) { if (cars == null) { cars = new ArrayList<String>(); } if (carId != null) { this.cars.add(car); } } public

MOXy marshal List<?> how to avoid that it shows the type in json results?

情到浓时终转凉″ 提交于 2019-12-11 14:09:48
问题 If I have to marshal a List<?> how to avoid that it shows the type? So the result of a marshalling List<?> is [{"type" : "person","id":"1"},{"type" : "person","id":"2"}] } and it give me also the type="Person" in the JSON results! How could I avoid that it shows me the type? Thank you 回答1: I haven't been able to reproduce the issue that you are seeing. Below is what I have tried. Domain Model (Person) package forum16966861; public class Person { private int id; private String name; public int

Does MOXy need anything special when using with schema-derived classes?

折月煮酒 提交于 2019-12-11 13:37:55
问题 I saw this question: Using Moxy as JAXB Implementation and setting jaxb.properties with more than one POJO package And wanted to ask the following: Does MOXy need anything special when using with schema-derived classes? For instance, are jaxb.properties files required in each of the packages? 回答1: The following applies to whether the classes were generated from an XML Schema, or were hand built POJOs. Specifying MOXy as the JAXB Provider for an Individual JAXBContext When creating a

How to avoid loading lazy bidirectional relationships with MOXy?

大城市里の小女人 提交于 2019-12-11 12:00:03
问题 My question is a follow up to this comment. I'm mixing JPA and JAXB (MOXy) annotations on the same class, which works fine most of the time. As described in the linked thread, @XmlInverseReference prevents cycle exceptions when bidirectional relationships are marshalled. But in order to detect the cycle, MOXy has to inspect the back reference of the linked entity, which leads to extra SQL SELECTs if a lazy relation needs to be populated. To illustrate the problem in detail, consider this made

Can MOXy serialize POJO with getters only without need to explicitly put annotation at each getter?

风流意气都作罢 提交于 2019-12-11 11:19:38
问题 So given I have class Name: class Name { private String first; private String middle; private String last; public getFirst() { return first; } public getMiddle() { return middle; } public getLast() { return last; } } I would like to serialize instances of this class using the mapping XML without having to list each property in the mapping XML: <java-types> <java-type name="Name"> <java-attributes> <xml-element java-attribute="first"/> <xml-element java-attribute="middle"/> <xml-element java

MOXy/JAXB “prototype pattern” - interface inheritance

ぃ、小莉子 提交于 2019-12-11 10:58:48
问题 I'm trying to implement a version of Gang of Four's Prototype Pattern using MOXy/JAXB 2.5.0. I want to be able to specify a list of items, some of which are "based on" others, i.e. copy their data from other instances. For reusability, I'd like to create an interface that any prototype-able object should implement, which will provide annotation for the properties necessary to support the pattern. @XmlRootElement(name="IPrototype") public interface IPrototype { /** * Acts as a "copy

How do I request a subset of XMLElements using MOXy?

眉间皱痕 提交于 2019-12-11 10:54:42
问题 I have a RESTful service that needs to return only a few of the XmlElements if "selectors" are submitted with the request. The URL will take the form of: /merchants/{merchantId}/profile?selectors=<field1|field2|....|fieldN> The selectors are optional, and so far I have implemented the service for the full set of elements to be returned for {merchantId} without selectors specified. Now I'm trying to figure out how to add in this added functionality. I'm sure this is covered in documentation

EclipseLink Moxy unmarshall and getValueByXPath gives null

白昼怎懂夜的黑 提交于 2019-12-11 08:05:09
问题 I use the below code to get unmarshall and query the unmarshelled object by Xpath. I am able to get the object after unmarshalling, but while querying by XPath, the value is coming as null. Do I need to specify any NameSpaceResolver? Please let me know if you are looking for any further information. My code: JAXBContext jaxbContext = (JAXBContext) JAXBContextFactory.createContext(new Class[] {Transaction.class}, null); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); StreamSource

How do I solve EclipseLink's (MOXy) 'getting property “eclipselink.oxm.metadata-source” is not supported'?

血红的双手。 提交于 2019-12-11 07:23:25
问题 I've got the following piece of code which I've put together mainly based on tutorials on EclipseLink's website: Partner p = new Partner(); p.setId(1); p.setKey("a"); p.setName("this is the name"); Map<String, Source> metadataSourceMap = new HashMap<String, Source>(); metadataSourceMap.put("com.company.pas.entity.partner", new StreamSource("/com/company/pas/entity/mapping/partner-pojo2xml.xml")); Map<String, Object> properties = new HashMap<String, Object>(); properties.put