unmarshalling

Override declared encoding during unmarshalling with JAXB

我与影子孤独终老i 提交于 2019-12-21 07:59:07
问题 I have an XML file with its encoding set within it: <?xml version="1.0" encoding="ISO-8859-15"?> but really file is encoded in UTF-8. Is there a way to override encoding declared in XML file when unmarshalling it with JAXB? 回答1: You can unmarshal the content from a java.io.Reader in order to supply the actual encoding: Unmarshaller unmarshaller = jc.createUnmarshaller(); InputStream inputStream = new FileInputStream("input.xml"); Reader reader = new InputStreamReader(inputStream, "UTF-8");

JAXB Unmarshalling: List of objects

可紊 提交于 2019-12-20 17:31:39
问题 I have @XmlRootElement(namespace = "http://www.w3.org/2005/Atom", name = "content") @XmlType(name = "course") public class Course implements Resource ... @XmlElementWrapper(name="subcourses") @XmlElement(name="course") List<Xlink> subcourses; //!? and Xlink class, which works fine in inline variable. public class Xlink { private String href; private String value; @XmlAttribute(namespace = "http://www.w3.org/1999/xlink") public String getHref() { return href; } public void setHref(String href)

Umarshalling MonthDay spring jackson json

醉酒当歌 提交于 2019-12-20 06:39:51
问题 Trying to make a restful service to save " PeriodeEnseignement " as below: package DomainModel.Enseignement.Notations; import java.time.MonthDay; import javax.persistence.Basic; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; import org.hibernate.annotations.GenericGenerator; import org.springframework.format.annotation.DateTimeFormat; import com.fasterxml.jackson.annotation

How to unmarshal a field that can be an array or a string in Go?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-20 05:38:15
问题 I'm trying to unmarshal this file: { "@babel/code-frame@7.0.0": { "licenses": "MIT", "repository": "https://github.com/babel/babel/tree/master/packages/babel-code-frame", "publisher": "Sebastian McKenzie", "email": "sebmck@gmail.com", "path": "/Users/lislab/workspace/falcon-enrolment/frontend-customer/node_modules/@babel/code-frame", "licenseFile": "/Users/lislab/workspace/falcon-enrolment/frontend-customer/node_modules/@babel/code-frame/LICENSE" }, "json-schema@0.2.3": { "licenses": [ "AFLv2

JAXB Unmarshalling XML string - Looping through all tags

别等时光非礼了梦想. 提交于 2019-12-20 04:58:35
问题 I am new to Java programming and I am doing Unmarshalling the following XML string. My task is get the names of the customers in this string. I have done it for one customer. I need to get all the customer names. I need help on the looping part. This works for one customer My Java code: XMLInputFactory xif = XMLInputFactory.newFactory(); Reader reader = new StringReader(response.toString()); XMLStreamReader xsr = xif.createXMLStreamReader(reader); while(xsr.hasNext()) { if(xsr.isStartElement(

Custom JSON mapping function in Go

大兔子大兔子 提交于 2019-12-20 03:13:13
问题 So I'm making a Go service that makes a call to a restful API, I have no control over the API I'm calling. I know that Go has a nice built in deserializer in NewDecoder->Decode, but it only works for struct fields that start with capital letters (aka public fields). Which poses a problem because the JSON I'm trying to consume looks like this: { "_next": "someValue", "data": [{/*a collection of objects*/}], "message": "success" } How the heck would I map "_next" ? 回答1: Use tags to specify the

How to control JAXB in-memory schema generation ordering/sequence?

五迷三道 提交于 2019-12-19 10:28:21
问题 I've got 3 xsd files that depend on each other to build my element definitions. Each xsd file has its own namespace. When I generate my classes using JAXB xjc, I get 3 corresponding packages. So far so good. My problem comes when I want to do schema validation with the unmarshaller. In order to avoid having to read in the xsd files, I generate the schemas on the fly from the class in question being unmarshalled. However, since the class depends on objects from 2 other packages, it is unable

Jersey: Consume all POST data into one object

谁说我不能喝 提交于 2019-12-19 03:21:42
问题 I am using Jersey 1.8 in my application. I am trying to consume POST data at the server. The data is of the type application/x-www-form-urlencoded . Is there a method to get all the data in one object, maybe a Map<String, Object> . I ran into Jersey's @Consumes(MediaType.APPLICATION_FORM_URLENCODED) . But using this would require me to use @FormParam , which can be tedious if the number of parameters are huge. Or maybe one way is this: @POST @Path("/urienodedeample") @Consumes(MediaType

when does JAXB unmarshaller.unmarshal returns a JAXBElement<MySchemaObject> or a MySchemaObject?

北城余情 提交于 2019-12-18 12:49:06
问题 I have two codes, in two different java projects, doing almost the same thing, (unmarshalling the input of a webservice according to an xsd-file). But in one case I should write this: (Input is a placeholder name) ( element is OMElement input ) ClassLoader clInput = input.ObjectFactory.class.getClassLoader(); JAXBContext jc = JAXBContext.newInstance("input", clInput); Unmarshaller unmarshaller = jc.createUnmarshaller(); Input input = (Input)unmarshaller.unmarshal( element.getXMLStreamReader()

How to validate an XML against schema using JAXB?

笑着哭i 提交于 2019-12-18 12:19:13
问题 I am working with XML and JAXB as I am unmarshalling and marshalling the XML into Java objects and vice versa. Now I am trying to validate our XML against our schema(test.xsd). Suppose if any required field is missing in my XML, then I would like to know which field is missing after validating the XML against schema test.xsd. public void unmarshal(final InputStream is) { final XMLInputFactory factory = XMLInputFactory.newInstance(); final XMLStreamReader reader = factory.createXMLStreamReader