Good Day Community,
I have a question regarding castor unmarshaling in java. As mentioned I am using castor to unmarshal a webservice response that contains a byte array (byte[])
.. please refer to below:
public class ViewReportResponse {
private String reportId;
private byte[] report;
//getters and setters here ...
I have used castor before to unmarhsal webservice responses, but admittedly, the responses previously where always strings. The problem lyes with the byte array returned as I believe castor chokes on unmarshaling it.
My castor-mapping file is provided below:
<class name="com.domain.reporting.client.service.ViewReportResponse">
<map-to xml="viewReportResponse"
xsi:schemaLocation="http://domain.com/schemas/reportingService/generateReport"
ns-uri="http://domain.com/schemas/reportingService/generateReport"
ns-prefix="ns2" />
<field name="reportId">
<bind-xml name="reportId"
node="element"
type="string"/>
</field>
<field name="report">
<bind-xml name="report"
node="element"
type="bytes" />
</field>
I'm not sure what I am missing, but the message is received but fails at the point of unmarshaling.
I've attached a clip of the error below.
org.springframework.oxm.UnmarshallingFailureException: Castor unmarshalling exception; nested exception is org.exolab.castor.xml.MarshalException: unable to find FieldDescriptor for 'report' in ClassDescriptor of viewReportResponse.
Please any assistance is much appreciated.
Thank-you kindly
Solved:
The general problem is not the maping to and from the byte[]. The problem is related to the use of namespace in this case.
<field name="reportId">
<bind-xml name="ns:reportId" xmlns:ns="http://domain.com/schemas/reportingService/generateReport"
node="element"
type="string"/>
<field name="report">
<bind-xml name="ns:report" xmlns:ns="http://domain.com/schemas/reportingService/generateReport"
node="element"
type="bytes"/>
This post is now effectively solved and closed.
Related
I've to parse Blockly generated XML code. Generally i use Xstream parser for parsing XML. But XStream parser not working since this XML has child tags same name as Parent tag.
I found this library which converts Blockly xml code to Java objects. But this library fails for Complex Blockly XML code shown below. I tried to edit library to enable parsing for the below xml code. But its not working.
<?xml version="1.0" encoding="UTF-8"?>
<block type="event_click" id="Bp64nx|xcR*L:(K(`u78" x="146" y="81">
<field name="Event_Type">none</field>
<field name="do_on_page_load">TRUE</field>
<statement name="action">
<block type="database_yes_no" id="#0OCYIX:}#uT?0[UbS=r">
<value name="Check_Name">
<block type="database_check_field" id="Sl-IEwB~/hv?9mQYYBB]">
<field name="Enum_Name">StockType</field>
<field name="Enum_Value">Serialised</field>
</block>
</value>
<statement name="Yes">
<block type="action_toggle_field" id="}X:#xcfp,!+bk7MA.sgJ">
<field name="action">show</field>
<field name="id">4930</field>
<next>
<block type="action_toggle_field" id="h)QgD#prJCVcm;BMG$VR">
<field name="action">hide</field>
<field name="id">4932</field>
<next>
<block type="action_toggle_field" id="1V{g?Cdh2ww}ihWhtovG">
<field name="action">show</field>
<field name="id">4961</field>
</block>
</next>
</block>
</next>
</block>
</statement>
<statement name="No">
<block type="action_toggle_field" id="InDTOg;B2!go_rD;WIb~">
<field name="action">hide</field>
<field name="id">4930</field>
<next>
<block type="action_toggle_field" id="f{Ae_|^jEb{CR5$?9Ku.">
<field name="action">show</field>
<field name="id">4932</field>
<next>
<block type="action_toggle_field" id="#-^o/f|Iv0WIids+VcJv">
<field name="action">hide</field>
<field name="id">4961</field>
</block>
</next>
</block>
</next>
</block>
</statement>
</block>
</statement>
</block>
I don't see much help on Blockly xml parsing.
Please let me know if there is a solution or library to parse Blockly generated XML code.
Thank you.
Stream-based XML parsers require you to maintain extra state, usually a stack. Simple if (tagName == 'block') {...} is not sufficient.
For your above example, the stack might look like:
block
statement
block
statement
block
next
block
next
block
field
Each item might have a pointer to the parsed object under construction, so you can add the child to it, and know what object to continue working on after an end tag.
While it uses XmlPullParser instead of a stream parser, you may want to look at com.google.blockly.model.BlockFactory.fromXml(..) in the blockly-android repo.
I have several different XML files. I want to display them in HTML format using JSP file.
The structure of these files can be different. They may have different depth and tag's names.
I've read about XSLT but I found only examples with manually created xsl. (I can't do that because i will have many different xml files).
How can i produce my html?
EDIT:
Example of form:
<form name="Company">
<field name="name" required="true" type="inputText"/>
<field name="registrationDate" required="true" type="date"/>
<field name="isActive" required="false" type="boolean"/>
<field name="unregistrationDate" type="date"/>
<field name="type" type="comboBox">
<values>
<value>type1</value>
<value>type3</value>
<value>type3</value>
</values>
<defaultSelected>type2</defaultSelected>
</field>
</form>
I recently upgraded BeanIO in my project from 1.2.3 to 2.0.6 and as part of that upgrade I had to modify some of my mappings that where using the Bean element to start using Segment element.
But what I noticed is that previously if a line in a stream had to little fields beanio would still initialize the object defined in the bean element in the mapping. Where as now in the same scenario the property that should be set with the object is simply set to null.
Old code that worked and populated the testName property with a empty Test object:
<bean name="testName" class="com.project.Test">
<field name="test1" type="string" default=""/>
<field name="test2" type="string" default=""/>
</bean>
New code that doesn't initialize the Test object and sets the testName property to null:
<segment name="testName" class="com.project.Test" minOccurs="0">
<field name="test1" type="string" default="" minOccurs="0"/>
<field name="test2" type="string" default="" minOccurs="0"/>
</segment>
Is there a way to force the Segment element to always initialize an object?
(Yes I do need to keep minOccurs="0" and no if I remove it, it doesn't solve the issue)
Thx,
goe
Try setting org.beanio.createMissingBeans=true in a beanio.properties file at the root of your classpath.
I was looking over this post of using JSR-303 to validate a collection of objects. The solution works great with annotations, but I can't seem to get it to work with the Hibernate Validator XML formatted configuration.
For example, I have code similar to this:
public class DataSet
{
Collection<Data> dataCollection;
public Collection<Data> getDataCollection() {...}
}
From there, I have a custom validator/annotation DataValidator/#ValidData.
In XML, I do this first:
<bean class="DataSet"
ignore-annotations="true">
<field name="dataCollection">
<valid/>
<constraint annotation="ValidData"/>
</field>
</bean>
However, I get the following exception:
Exception in thread "main" javax.validation.UnexpectedTypeException: No validator could be found for type: java.util.Collection<DataSet>
So I swap the <valid> tag with the <constraint> one in the XML. It seems this is not valid with the XSD schema and the XML can no longer be parsed.
<bean class="DataSet"
ignore-annotations="true">
<field name="dataCollection">
<constraint annotation="ValidData"/>
<valid/>
</field>
</bean>
Exception in thread "main" javax.validation.ValidationException: Error parsing mapping file.
Does anyone know how I can use XML to validate this collection with must custom validator?
The key was adding a class-level constraint annotation in the XML to the Data POJO itself.
<bean class="DataSet"
ignore-annotations="true">
<field name="dataCollection">
<valid/>
</field>
</bean>
<bean class="Data" ignore-annotations="true">
<class>
<constraint annotation="ValidData"/>
</class>
</bean>
I am trying the Data Import Handler for MySQL Database.
I added the DIhandler in solrconfig.xml, created a data-config.xml according to my database scheme and also added a field in the schema.xml which was different. I am connecting with MySQL database
After i connect and I run the dataimport?command=full-import i get this response
"00C:\solr\conf\data-config.xmlfull-importidle1102011-03-05 15:01:04Indexing completed. Added/Updated: 0 documents. Deleted 0 documents.2011-03-05 15:01:042011-03-05 15:01:040:0:0.400This response format is experimental. It is likely to change in the future."
The xml files are in this http://pastebin.com/iKebKGSZ
<field column="manu" name="manu" />
<field column="id" name="id" />
<field column="weight" name="weight" />
<field column="price" name="price" />
<field column="popularity" name="popularity" />
<field column="instock" name="inStock" />
<field column="includes" name="includes" />
Are these fields also in your schema.xml?
I couldnt see them in the pastebin link. Make sure you have all fields in your schema as well.