Using jackson xml mapper to map java list in xml - java

I've a problem with xml Mapper.
I'm using the com.fasterxml.jackson.xml.XmlMapper library.
Practically, this is my java bean that map the values in this way:
#JsonAutoDetect
#JacksonXmlRootElement(localName ="Patient")
public class Patient implements Serializable {
private static final long serialVersionUID = -2981849269841429849L;
#JsonProperty("patientId")
#JacksonXmlProperty(isAttribute = true)
private String patientId;
#JsonProperty("patientName")
#JacksonXmlProperty(isAttribute = true)
private String patientName;
#JacksonXmlProperty(localName = "Series")
#JacksonXmlElementWrapper(useWrapping=false)
private ArrayList<Serie> listSerie;
}
and generate in the main class the xml with:
Wado mapp = new Wado();
mapp.setvalue("bla bla");
String xmlWado = new XmlMapper().writeValueAsString(wado);
the result is:
<Patient patientId="" patientName="">
<Series>
<Series></Series>
<Series></Series>
<Series></Series>
</Series>
that's not I was expected. I want:
<Patient patientId="" patientName="">
<Series></Series>
<Series></Series>
<Series></Series>
Any suggestions?

Related

Jackson XML - Deserialize from specific node

I'm new to Jackson XML and I would like to do the following:
Here is the XML I'd like to convert to Java DTO:
<s:Envelope
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<cotacaoTaxaCambioResponse
xmlns="http://tempuri.org/">
<cotacaoTaxaCambioResult
xmlns:a="http://schemas.datacontract.org/2004/07/Exchange"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:TaxasCambio>
<a:CotacaoTaxaCambio>
<a:CLIENTEC>0</a:CLIENTEC>
<a:CLIENTEV>0</a:CLIENTEV>
<a:COMERCIALC>0</a:COMERCIALC>
<a:COMERCIALV>30</a:COMERCIALV>
<a:DATA>2021-12-15T00:00:00</a:DATA>
<a:HORARIO>1027</a:HORARIO>
<a:MOEDA>978</a:MOEDA>
<a:PARIDADEC>1</a:PARIDADEC>
<a:PARIDADEV>1</a:PARIDADEV>
<a:TURISMOC>0</a:TURISMOC>
<a:TURISMOV>30</a:TURISMOV>
</a:CotacaoTaxaCambio>
</a:TaxasCambio>
<a:serviceStatus>
<a:CODRETORNO>0</a:CODRETORNO>
<a:MENSAGEM>Sucesso</a:MENSAGEM>
<a:MENSAGEMEN>OK</a:MENSAGEMEN>
<a:NRREFERENCE>0</a:NRREFERENCE>
</a:serviceStatus>
</cotacaoTaxaCambioResult>
</cotacaoTaxaCambioResponse>
</s:Body>
</s:Envelope>
Info I need is attributes of a:CotacaoTaxaCambio node.
Created this DTO
#JacksonXmlRootElement(localName = "a:CotacaoTaxaCambio")
public class CotacaoResDTO {
#JacksonXmlProperty(localName = "a:DATA")
private String data;
#JacksonXmlProperty(localName = "a:HORARIO")
private String hora;
#JacksonXmlProperty(localName = "a:MOEDA")
private String codMoeda;
#JacksonXmlProperty(localName = "a:COMERCIALV")
private Double valorComercial;
#JacksonXmlProperty(localName = "a:TURISMOV")
private Double valorTurismo;
}
If I set this subset as input, it does work:
<a:CotacaoTaxaCambio>
<a:CLIENTEC>0</a:CLIENTEC>
<a:CLIENTEV>0</a:CLIENTEV>
<a:COMERCIALC>0</a:COMERCIALC>
<a:COMERCIALV>30</a:COMERCIALV>
<a:DATA>2021-12-15T00:00:00</a:DATA>
<a:HORARIO>1027</a:HORARIO>
<a:MOEDA>978</a:MOEDA>
<a:PARIDADEC>1</a:PARIDADEC>
<a:PARIDADEV>1</a:PARIDADEV>
<a:TURISMOC>0</a:TURISMOC>
<a:TURISMOV>30</a:TURISMOV>
</a:CotacaoTaxaCambio>
But it doesn't deserialize if I set full xml as input.
Is there any configuration or anotation that I can use to archieve this?
Thanks in advance,
Unfortunately at the moment the jackson library does not support directly the SOAP protocol, but you can read the part you are interested with the XMLStreamReader class directly pointing the involved tag:
XMLInputFactory f = XMLInputFactory.newFactory();
XMLStreamReader sr = f.createXMLStreamReader(new FileInputStream(xml));
XmlMapper mapper = new XmlMapper();
sr.nextTag();
while (!sr.getLocalName().equals("CotacaoTaxaCambio")) {
sr.nextTag();
}
CotacaoResDTO value = mapper.readValue(sr, CotacaoResDTO.class);
sr.close();
You have to modify also your CotacaoResDTO class ignoring the unknown properties :
#JsonIgnoreProperties(ignoreUnknown = true)
public class CotacaoResDTO {
#JacksonXmlProperty(localName = "DATA")
private String data;
#JacksonXmlProperty(localName = "HORARIO")
private String hora;
#JacksonXmlProperty(localName = "MOEDA")
private String codMoeda;
#JacksonXmlProperty(localName = "COMERCIALV")
private Double valorComercial;
#JacksonXmlProperty(localName = "TURISMOV")
private Double valorTurismo;
}

Jackson Polymorphic Deserialization Issue/Question

I have a class representing the root node and want to deserialize data to different subclasses based on the value of action. The fields must be final.
#EqualsAndHashCode
#ToString
public final class SeMessage {
#Getter
private final String action;
#Getter
private final SeMessageData data;
#JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public SeMessage(
#JsonProperty("action") final String action,
#JsonProperty("data")
#JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "action", include = JsonTypeInfo.As.EXTERNAL_PROPERTY)
#JsonSubTypes({
#JsonSubTypes.Type(value = Se155QuestionsActiveMessageData.class, name = "155-questions-active")
}) final SeMessageData data
) {
super();
this.action = action;
this.data = data;
}
}
Here are SeMessageData and Se155QuestionsActiveMessageData:
public abstract class SeMessageData {
SeMessageData() {
super();
}
}
#EqualsAndHashCode
#ToString
public final class Se155QuestionsActiveMessageData extends SeMessageData {
#Getter
private final String siteBaseHostAddress;
#Getter
private final Long id;
#Getter
private final String titleEncodedFancy;
#Getter
private final String bodySummary;
#Getter
private final List<String> tags;
#Getter
private final Long lastActivityDate;
#Getter
private final String url;
#Getter
private final String ownerUrl;
#Getter
private final String ownerDisplayName;
#Getter
private final String apiSiteParameter;
#JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public Se155QuestionsActiveMessageData(
#JsonProperty("siteBaseHostAddress") final String siteBaseHostAddress,
#JsonProperty("id") final Long id,
#JsonProperty("titleEncodedFancy") final String titleEncodedFancy,
#JsonProperty("bodySummary") final String bodySummary,
#JsonProperty("tags") final List<String> tags,
#JsonProperty("lastActivityDate") final Long lastActivityDate,
#JsonProperty("url") final String url,
#JsonProperty("ownerUrl") final String ownerUrl,
#JsonProperty("ownerDisplayName") final String ownerDisplayName,
#JsonProperty("apiSiteParameter") final String apiSiteParameter
) {
super();
this.siteBaseHostAddress = siteBaseHostAddress;
this.id = id;
this.titleEncodedFancy = titleEncodedFancy;
this.bodySummary = bodySummary;
this.tags = tags;
this.lastActivityDate = lastActivityDate;
this.url = url;
this.ownerUrl = ownerUrl;
this.ownerDisplayName = ownerDisplayName;
this.apiSiteParameter = apiSiteParameter;
}
}
Topic #1:
Doing so causes an exception to be thrown:
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `com.oliveryasuna.stackexchange.websocket.message.data.Se155QuestionsActiveMessageData` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('{"siteBaseHostAddress":"stackoverflow.com","id":70098765,"titleEncodedFancy":"How to avoid the command execution when appending lines to a file","bodySummary":"I'm trying to save the content of script into a file using command line, but I noticed that when the tee command detects linux commands such as $(/usr/bin/id -u), it execute the commands rather than ...","tags":["linux","append","tee"],"lastActivityDate":1637767762,"url":"https://stackoverflow.com/questions/70098765/how-to-avoid-the-command-execution-when-appending-lines-to-a-file","ownerUrl":"https://stackoverflow.com/users/17499564/alex","ownerDisplayName":"Alex","apiSiteParameter":"stackoverflow"}')
at [Source: (String)"{"action":"155-questions-active","data":"{\"siteBaseHostAddress\":\"stackoverflow.com\",\"id\":70098765,\"titleEncodedFancy\":\"How to avoid the command execution when appending lines to a file\",\"bodySummary\":\"I'm trying to save the content of script into a file using command line, but I noticed that when the tee command detects linux commands such as $(/usr/bin/id -u), it execute the commands rather than ...\",\"tags\":[\"linux\",\"append\",\"tee\"],\"lastActivityDate\":1637767762,\"url\":\"[truncated 248 chars]; line: 1, column: 748]
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63)
at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1588)
at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1213)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer._deserializeFromString(StdDeserializer.java:311)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromString(BeanDeserializerBase.java:1495)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:207)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:197)
at com.fasterxml.jackson.databind.jsontype.impl.AsArrayTypeDeserializer._deserialize(AsArrayTypeDeserializer.java:120)
at com.fasterxml.jackson.databind.jsontype.impl.AsArrayTypeDeserializer.deserializeTypedFromObject(AsArrayTypeDeserializer.java:61)
at com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserializeWithType(AbstractDeserializer.java:263)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:539)
at com.fasterxml.jackson.databind.deser.impl.ExternalTypeHandler._deserialize(ExternalTypeHandler.java:359)
at com.fasterxml.jackson.databind.deser.impl.ExternalTypeHandler.complete(ExternalTypeHandler.java:302)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeUsingPropertyBasedWithExternalTypeId(BeanDeserializer.java:1090)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeWithExternalTypeId(BeanDeserializer.java:931)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:360)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:195)
at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:322)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4593)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3548)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3516)
at com.oliveryasuna.stackexchange.websocket.SeWebSocketHandler.handleTextMessage(SeWebSocketHandler.java:56)
at org.springframework.web.socket.handler.AbstractWebSocketHandler.handleMessage(AbstractWebSocketHandler.java:43)
at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter.handleTextMessage(StandardWebSocketHandlerAdapter.java:114)
at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter.access$000(StandardWebSocketHandlerAdapter.java:43)
at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter$3.onMessage(StandardWebSocketHandlerAdapter.java:85)
at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter$3.onMessage(StandardWebSocketHandlerAdapter.java:82)
at org.apache.tomcat.websocket.WsFrameBase.sendMessageText(WsFrameBase.java:415)
at org.apache.tomcat.websocket.WsFrameBase.processDataText(WsFrameBase.java:515)
at org.apache.tomcat.websocket.WsFrameBase.processData(WsFrameBase.java:301)
at org.apache.tomcat.websocket.WsFrameBase.processInputBuffer(WsFrameBase.java:133)
at org.apache.tomcat.websocket.WsFrameClient.processSocketRead(WsFrameClient.java:95)
at org.apache.tomcat.websocket.WsFrameClient.resumeProcessing(WsFrameClient.java:212)
at org.apache.tomcat.websocket.WsFrameClient.access$500(WsFrameClient.java:31)
at org.apache.tomcat.websocket.WsFrameClient$WsFrameClientCompletionHandler.doResumeProcessing(WsFrameClient.java:189)
at org.apache.tomcat.websocket.WsFrameClient$WsFrameClientCompletionHandler.completed(WsFrameClient.java:163)
at org.apache.tomcat.websocket.WsFrameClient$WsFrameClientCompletionHandler.completed(WsFrameClient.java:148)
at org.apache.tomcat.websocket.AsyncChannelWrapperSecure$WrapperFuture.complete(AsyncChannelWrapperSecure.java:471)
at org.apache.tomcat.websocket.AsyncChannelWrapperSecure$ReadTask.run(AsyncChannelWrapperSecure.java:338)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
I tried using a custom deserializer, but the same exception is thrown. You'll notice that this uses regex, which is my ultimate goal (see Topic #2).
final class Deserializer extends StdDeserializer<SeMessage> {
private static final Map<String, Class<? extends SeMessageData>> ACTION_TYPE_MAP = Map.ofEntries(
Map.entry("^155-questions-active$", Se155QuestionsActiveMessageData.class),
Map.entry("^(?!155)\\d+-questions-(?:active|newest(?:-tag-[a-z0-9]+)?)$", SeQuestionsMessageData.class)
);
private Deserializer() {
super(SeMessage.class);
}
#Override
public final SeMessage deserialize(final JsonParser parser, final DeserializationContext context) throws IOException, JsonProcessingException {
final JsonNode json = parser.getCodec().readTree(parser);
final String action = json.get("action").textValue();
for(final Map.Entry<String, Class<? extends SeMessageData>> actionTypeEntry : ACTION_TYPE_MAP.entrySet()) {
final String actionRegex = actionTypeEntry.getKey();
if(action.matches(actionRegex)) {
final Class<? extends SeMessageData> type = actionTypeEntry.getValue();
final JsonNode dataJson = json.get("data");
final SeMessageData data = parser.getCodec().treeToValue(dataJson, type);
return new SeMessage(action, data);
}
}
throw new IOException("Unsupported action: " + action + ".");
}
}
Odd enough, if I deserialize data with the followingly (instead of treeToValue), no exception is thrown. The OBJECT_MAPPER is just a plain instance of ObjectMapper without any added modules or configuration.
final String dataJson = json.get("data").textValue();
final SeMessageData data = JacksonUtil.OBJECT_MAPPER.readValue(dataJson, type);
return new SeMessage(action, data);
Topic #2:
Once Topic #1 is resolved, I will still want to avoid using a custom deserializer. You'll notice in the custom deserialize class above that I match the value of action with regex. Is it possible to override the functionality of #JsonTypeInfo and #JsonSubTypes, such that the name argument is regex and the value of action is matched that way?

Jackson parsing XML

I'm trying to serialize POJO class to Amazon XML format to aggregate the date from the service.
The goal is to have an xml like:
<ShipmentEventList>
<ShipmentEvent>
<ShipmentItemList>
<ShipmentItem></ShipmentItem>
</ShipmentItemList>
<AmazonOrderId>AAAA</AmazonOrderId>
<PostedDate>BBBB</PostedDate>
<MarketplaceName>CCCC</MarketplaceName>
<SellerOrderId>DDDD</SellerOrderId>
</ShipmentEvent>
</ShipmentEventList>
Here are my POJO classes
ShipmentEventList
public class ShipmentEventList {
#JacksonXmlElementWrapper(localName = "ShipmentEventList")
#JacksonXmlProperty(localName = "ShipmentEvent")
private List<ShipmentEvent> shipmentEventList;
}
ShipmentEvent
#JacksonXmlRootElement(localName = "ShipmentEvent")
public class ShipmentEvent {
#JacksonXmlElementWrapper(localName = "ShipmentItemList")
private List<ShipmentItem> shipmentItemList;
#JacksonXmlProperty(localName = "AmazonOrderId")
private String amazonOrderId;
#JacksonXmlProperty(localName = "PostedDate")
private String postedDate;
#JacksonXmlProperty(localName = "MarketplaceName")
private String marketplaceName;
#JacksonXmlProperty(localName = "SellerOrderId")
private String sellerOrderId;
}
Unfortunatelly, as a result of the serialization I have:
<ShipmentEventList>
<ShipmentEventList>
<ShipmentEvent>
<AmazonOrderId>A</AmazonOrderId>
<PostedDate>B</PostedDate>
<MarketplaceName>C</MarketplaceName>
<SellerOrderId>D</SellerOrderId>
</ShipmentEvent>
<ShipmentEvent>
<AmazonOrderId>B</AmazonOrderId>
<PostedDate>C</PostedDate>
<MarketplaceName>D</MarketplaceName>
<SellerOrderId>E</SellerOrderId>
</ShipmentEvent>
</ShipmentEventList>
</ShipmentEventList>
Could you explain me how does the serialization of collections work in Jackson?
You need to set useWrapping flag to false:
class ShipmentEventList {
#JacksonXmlElementWrapper(useWrapping = false)
#JacksonXmlProperty(localName = "ShipmentEvent")
private List<ShipmentEvent> shipmentEventList;
}

unable to parse CSV with `CsvParser` abstract class mapping but works with JSON mapper

Unable to parse CSV files to Object type,
CsvMapper not working with polymorphism, while JSON mapper works with jsonString.
#Getter
#JsonTypeInfo(use = JsonTypeInfo.Id.NAME,
property = "type", visible = true,
include = JsonTypeInfo.As.PROPERTY)
#JsonSubTypes({
#Type(value = FHR.class, name = "FHR"),
#Type(value = BHR.class, name = "BHR")})
public class PaymentBatchRecord {
protected String type;
}
#Getter
#Setter
#JsonPropertyOrder({
// "type",
"transmit_id",
"password",
"creation_date",
"creation_time",
"file_format_code",
"file_reference_code"
})
class FHR extends PaymentBatchRecord implements Serializable {
private final static long serialVersionUID = -584359005702082280L;
// #JsonProperty("type")
// private String type;
#JsonProperty("transmit_id")
private String transmitId;
#JsonProperty("password")
private String password;
#JsonProperty("creation_date")
private String creationDate;
#JsonProperty("creation_time")
private String creationTime;
#JsonProperty("file_format_code")
private String fileFormatCode;
#JsonProperty("file_reference_code")
private String fileReferenceCode;
}
#Setter
#Getter
#JsonPropertyOrder({
// "type",
"transaction_type",
"merchant_id",
"merchant_name",
"batch_entry_description",
"batch_reference_code",
"batch_number"
})
class BHR extends PaymentBatchRecord implements Serializable {
private final static long serialVersionUID = 1650905882208990490L;
// #JsonProperty("type")
// private String type;
#JsonProperty("transaction_type")
private String transactionType;
#JsonProperty("merchant_id")
private String merchantId;
#JsonProperty("merchant_name")
private String merchantName;
#JsonProperty("batch_entry_description")
private String batchEntryDescription;
#JsonProperty("batch_reference_code")
private String batchReferenceCode;
#JsonProperty("batch_number")
private Integer batchNumber;
}
and here is I'm trying to de-serialize
CsvMapper mapper = new CsvMapper();
// uncomment it to run but with all the null values
// mapper.enable(CsvParser.Feature.IGNORE_TRAILING_UNMAPPABLE)
;
CsvSchema sclema = mapper.schemaFor(PaymentBatchRecord.class)
.withoutHeader();
MappingIterator<PaymentBatchRecord> iterator = mapper
.readerFor(PaymentBatchRecord.class)
.with(sclema)
.readValues(in);
List<PaymentBatchRecord> ppojos = iterator.readAll();
and here is the sample csv input
FHR,BILLER_1,"biller1pwd","20200224","091503","CSV","202002240915031"
BHR,"PMT","BILLER_1","BILLER 1 NAME","UTILITY BILL",,1
Exception I got:
Exception in thread "main" com.fasterxml.jackson.dataformat.csv.CsvMappingException: Too many entries: expected at most 1 (value #1 (8 chars) "BILLER_1")
at [Source: (com.fasterxml.jackson.dataformat.csv.impl.UTF8Reader); line: 1, column: 5]
at com.fasterxml.jackson.dataformat.csv.CsvMappingException.from(CsvMappingException.java:28)
at com.fasterxml.jackson.dataformat.csv.CsvParser._reportCsvMappingError(CsvParser.java:1246)
at com.fasterxml.jackson.dataformat.csv.CsvParser._handleExtraColumn(CsvParser.java:1001)
at com.fasterxml.jackson.dataformat.csv.CsvParser._handleNextEntry(CsvParser.java:862)
at com.fasterxml.jackson.dataformat.csv.CsvParser.nextToken(CsvParser.java:609)
at com.fasterxml.jackson.core.util.JsonParserSequence.switchAndReturnNext(JsonParserSequence.java:234)
at com.fasterxml.jackson.core.util.JsonParserSequence.nextToken(JsonParserSequence.java:152)
at com.fasterxml.jackson.core.JsonParser.nextFieldName(JsonParser.java:861)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:295)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:189)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:161)
at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer._deserializeTypedForId(AsPropertyTypeDeserializer.java:130)
at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromObject(AsPropertyTypeDeserializer.java:97)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeWithType(BeanDeserializerBase.java:1196)
at com.fasterxml.jackson.databind.deser.impl.TypeWrappedDeserializer.deserialize(TypeWrappedDeserializer.java:68)
at com.fasterxml.jackson.databind.MappingIterator.nextValue(MappingIterator.java:280)
at com.fasterxml.jackson.databind.MappingIterator.readAll(MappingIterator.java:320)
at com.fasterxml.jackson.databind.MappingIterator.readAll(MappingIterator.java:306)

Jackson Serialization of XML with multiple attributes

Trying to figure out how to serialize an xml payload with jackson that has multiple attributes(?) as well as namespaces or locals.
I need the payload to look like this:
<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs"
xmlns:ogc="http://www.opengis.net/ogc" xmlns:fade="http://www.bit-sys.com/fade" service="WFS" version="1.1.0" resultType="results" maxFeatures="150001" outputFormat="application/json">
<wfs:Query srsName="EPSG:4326" typeName="ExampleTypeName">
<Filter xmlns="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml">
...
And I am working on creating a pojo to use to map the data necessary for this payload to the correct location, but just having trouble differentiating the namespace vs localName parts. The pojo I have so far isn't really producing the desired result (even for the first <GetFeature /> part.
public class MyXmlObject {
#JacksonXmlRootElement(localName = "wfs", namespace = "wfs")
class GetFeature {
#JacksonXmlProperty(isAttribute = true)
private String wfs = "http://www.opengis.net/wfs";
#JacksonXmlProperty(isAttribute = true)
private String ocg = "http://www.opengis.net/ogc";
#JacksonXmlProperty(isAttribute = true)
private String fade = "http://www.bit-sys.com/fade";
#JacksonXmlProperty(isAttribute = true)
private String service;
#JacksonXmlRootElement(localName = "wfs")
public class Query {
#JacksonXmlProperty(isAttribute = true)
private String srsName = "exampleSrsName";
#JacksonXmlProperty(isAttribute = true)
private String typeName = "exampleTypeName";
}
}
}
Right now only running a simple test to see how my xml payload looks as I work on it produces <MyXmlObject /> with nothing else in it, not too sure what I am doing wrong.
#Test
public void whenJavaSerializedToXmlStr_thenCorrect()
throws JsonProcessingException {
XmlMapper xmlMapper = new XmlMapper();
xmlMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
String xml = xmlMapper.writeValueAsString(new MistXmlObject());
System.out.print(xml);
}

Categories

Resources