How do I make a bytecode-only Field be #XmlTransient?
When a class is woven by AspectJ, its bytecode (but not its source code) receives an extra injected static field:
private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_0;
This extra field is not treated as XmlTransient by MOXy, and causes an Exception when trying to create a JAXBContext:
Caused by: javax.xml.bind.JAXBException:
Exception Description: The class org.aspectj.runtime.reflect.JoinPointImpl$StaticPartImpl requires a zero argument constructor or a specified factory method. Note that non-static inner classes do not have zero argument constructors and are not supported.
- with linked exception:
[Exception [EclipseLink-50001] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.JAXBException
Exception Description: The class org.aspectj.runtime.reflect.JoinPointImpl$StaticPartImpl requires a zero argument constructor or a specified factory method. Note that non-static inner classes do not have zero argument constructors and are not supported.]
Possible solutions
According to the EclipseLink MOXy example, it seems that I should be able to make this field #XmlTransient by creating a file called eclipselink-oxm.xml with the content below, and place the file within the directory src/main/resources/META-INF. However, this does not work.
How should I proceed here?
eclipselink-oxm.xml
<?xml version="1.0"?>
<xml-bindings
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="${eclipselink.version}">
<java-types>
<java-type name="se.mithlond.services.organisation.model.address.CategorizedAddress">
<java-attributes>
<xml-transient java-attribute="ajc$tjp_0"/>
</java-attributes>
</java-type>
<!--java-type name="org.aspectj.runtime.reflect.JoinPointImpl$StaticPartImpl" xml-transient="true" />
<java-type name="org.aspectj.runtime.reflect.JoinPointImpl" xml-transient="true" / -->
</java-types>
</xml-bindings>
Related
I'm migrating my application from wildfly 10 to wildfly 14 and I'm using resteasy 3.1.4 with jackson2.
I have a strange behaviour with the response of some rest services: not all the fields are returned (and I'm sure they're extracted from mongodb). The only warning I see when deploying my application is:
WFLYRS0018: Explicit usage of Jackson annotation in a JAX-RS deployment; the system will disable JSON-B processing for the current deployment. Consider setting the 'resteasy.preferJacksonOverJsonB' property to 'false' to restore JSON-B.
In the response I have two classes:
public class Field implements Serializable {
private static final long serialVersionUID = -230381150649916138L;
private String name; // returned in response
private FieldsTypeEnum type; // NOT returned in response
private List<String> comboValues; // NOT returned in response
private boolean required; // NOT returned in response
//All getters and setters
}
public class ConfigurationField extends Field {
private static final long serialVersionUID = -2727277793405725817L;
private Integer row; // returned in response
private boolean useForCalendar; // returned in response
//All getters and setters
}
Any help or suggest or idea is really appreciated
Thanks
It has been 6 months since the question was asked. However, I faced the similar issue a few days ago on Wildfly 16.
The issue was caused by JsonBindingProvider takes precedence over the other providers for dealing with JSON payloads, particular the Jackson one.
https://issues.jboss.org/browse/RESTEASY-1911
Please see documentation here.
https://github.com/resteasy/Resteasy/commit/f6ddef5accb88d924e3d14ab15e081c79136fe55
It can be fixed by 2 ways without having to update your model (POJO) objects:
Adding system property when starting up Wildfly -Dresteasy.preferJacksonOverJsonB=true
Exclude jsonb module in jboss-deployment-structure.xml
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
<deployment>
<exclusions>
<module name="org.jboss.resteasy.resteasy-json-binding-provider" />
</exclusions>
</deployment>
</jboss-deployment-structure>
If you do not want to change Wildfly configuration, you have to update you models to conform with JsonB specification, e.g. public your private fields in your models, or adding suitable #Jsonb annotations to your fields, ... like here, https://www.baeldung.com/java-json-binding-api.
Based on the answer from Soner, this helped me when added to web.xml:
<context-param>
<param-name>resteasy.preferJacksonOverJsonB</param-name>
<param-value>true</param-value>
</context-param>
I prefer this solution in order to keep the configuration within the app code.
I had similar problems within Wildfly 21. Adding a jboss-deployment-structure.xml like:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.3">
<deployment>
<exclusions>
<module name="org.jboss.resteasy.resteasy-json-binding-provider"/>
</exclusions>
<dependencies>
<module name="org.jboss.resteasy.resteasy-jackson2-provider" />
</dependencies>
</deployment>
</jboss-deployment-structure>
didn't help
For me the working solution was to add following line into the Wildfly standalone.conf to prefer jackson:
JAVA_OPTS="$JAVA_OPTS -Dresteasy.preferJacksonOverJsonB=true"
I have inherited a web project that uses WCF in a separate project of my solution to get the data. I'm not familiar with WCF but I was asked to see if I could send another parameter. A developer that is responsible for the actual Web Service will make the adjustment for the extra parameter on his side.
I did a search in the solution for the property called crewMemberConMonthField so I could just copy and paste a new one called crewMemberConMonthField2. I found it in the References.cs and in a FH_FTPService.xsd file.
In the .xsd file I copy and pasted the XML and just changed the name. I then went to the refernces.cs file and added another parameter with the new name (crewMemberConMonthField2). Since I'm using VS 2015 it gives me the option to refactor the name but when I do I get a warning message that basically says "the file could not be refactored. The current object is auto-generated by the Wcf Client Generator and cannot be renamed".
I've been searching for information about this but everything I'm finding is try to walk me through created a WCF. When I look through those examples I'm not seeing anything about a Wcf Client Generator.
I was looking to see if anyone could maybe point me in the right direction.
Here is some of what I have in the reference.cs
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.18408")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://sitename.com/FH_FTPService/")]
public partial class StartRequestType : object, System.ComponentModel.INotifyPropertyChanged {
private StartRequestTypePartition partitionField;
private string crewMemberConMonthField;
private string crewMemberConMonthField2;
private string sequenceConMonth1Field;
private string sequenceConMonth2Field;
and this is in my .xsd file
<schema xmlns:tns="http://sitename.com/FH_FTPService/" elementFormDefault="qualified" targetNamespace="http://sitename.com/FH_FTPService/" xmlns="http://www.w3.org/2001/XMLSchema">
<complexType name="StartRequestType">
<sequence>
<element name="CrewMemberConMonth">
<simpleType>
<restriction base="string">
<length value="7" />
<pattern value="^(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)\d{4}$" />
</restriction>
</simpleType>
</element>
<element name="CrewMemberConMonth2">
<simpleType>
<restriction base="string">
<length value="7" />
<pattern value="^(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)\d{4}$" />
</restriction>
</simpleType>
</element>
The global property is not being resolved from properties file, as a result of which mmc deployment fails. Any ides why what could be wrong?
<context:property-placeholder location="airports.properties" />
<global-property name="airportslist" value="${airportslist}" />
Getting the following exception --
com.mulesoft.mmc.agent.v3.dto.DeploymentException: Unexpected exception parsing XML document from URL [file:/arprt/mule-esb-ee/mule-enterprise-standalone-3.3.0/apps/myapp-1.0.0-SNAPSHOT/myapp-config.xml]; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'airportslist' (org.mule.api.lifecycle.InitialisationException) (org.mule.api.config.ConfigurationException)
at com.mulesoft.mmc.agent.service.impl.ApplicationServiceImpl.deploy(ApplicationServiceImpl.java:245)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
airports.properties contains the above mentioned property:
airportslist={'SFO', 'YYZ', 'DFW'}
You do not need to declare a global-property if the property is defined in a properties file and loaded with the context:property-placeholder.
Just remove:
<global-property name="airportslist" value="${airportslist}" />
and use ${airportslist} anywhere you need it in your config.
I am attempting to unmarshal an XML data stream with EclipseLink MOXy with an XPath using the contains function.
When I apply the sample XPath directly to the sample XML data stream I get the correct value returned (Ref_number_1). However, when I unmarshal this using MOXy, the value that is set for refNumber1 is "Ref_number_2".
Does MOXy not support this type of XPath? It would appear that it at least is understanding it because it's not throwing an error, just setting the wrong value.
Anyone have any experience with this sort of thing? Know of a better approach?
Thanks for any help.
Marshal code:
String s = //xml stream from restful service (see xml example below);
StringReader sr = new StringReader(s);
ReferenceNumber refNum = (ReferenceNumber)marshaller.unmarshal(
new StreamSource(sr));
Member annotation:
#XmlPath("Header/ReferenceNumbers/ReferenceNumber[contains(ReferenceNumberType, \"REF_NUMBER_TYPE_1\")]/ReferenceNumber/text()")
private String refNumber1;
XML data:
<?xml version="1.0" encoding="UTF-8"?>
<Document>
<Header>
<ReferenceNumbers>
<ReferenceNumber>
<ReferenceNumber>Ref_number_1</ReferenceNumber>
<ReferenceNumberType>REF_NUMBER_TYPE_1</ReferenceNumberType>
</ReferenceNumber>
<ReferenceNumber>
<ReferenceNumber>Ref_number_2</ReferenceNumber>
<ReferenceNumberType>REF_NUMBER_TYPE_2</ReferenceNumberType>
</ReferenceNumber>
</ReferenceNumbers>
</Header>
</Document>
Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group.
Currently MOXy does not support XPaths of that form. Currently a conditional check must be on an attribute contained within the element such as (see: http://blog.bdoughan.com/2011/03/map-to-element-based-on-attribute-value.html).
#XmlPath("personal-info/name[#type='first']/text()")
String firstName;
I have entered the following bug so that we improve the validation that we do on our #XmlPath annotation:
http://bugs.eclipse.org/397101
I am also interested in the use case described in your question. Would you mind entering an enhancement requires against the MOXy component for this:
https://bugs.eclipse.org/bugs/enter_bug.cgi?product=EclipseLink
I'm using the json plugin that comes with struts 2 (json-lib-2.1.jar) and trying to follow the website to set it up.
Here's my struts.xml
<struts>
<package name="example" extends="json-default">
<action name="AjaxRetrieveUser" class="actions.view.RetrieveUser">
<result type="json"/>
</action>
</package>
</struts>
but I get this warning:
SEVERE: Unable to find parent packages json-default
Is there something else I'm supposed to do?
Edit:
I added this method to my RetrieveUser:
public Map<String,Object> getJsonModel()
{
return jsonModel;
}
And my struts.xml looks like this:
<struts>
<package name="example" extends="json-default">
<action name="AjaxRetrieveUser" class="actions.view.RetrieveUser">
<result type="json"/>
<param name="root">jsonModel</param>
</action>
</package>
</struts>
However, I don't think the response is going from the RetrieveUser class to the javascript. I'm using firebug and no request gets sent.
I believe that net.sf.json-lib is just a toolset you can use in your Java to build up JSON-ready objects, suitable to be returned by actions such as you describe.
Probably, you need to include struts-json-plugin - make sure its version matches your struts version.
I notice also that as written, your action will attempt to return RetrieveUser, serialized. Most implementations I've done/seen specify the root object to be returned, by adding
<param name="root">jsonUser</param>
Under the tag, and define this method in RetrieveUser
public Map<String, Object> getJsonUser()
[This is mentioned in the Sruts2 doc]. Hope that helps.
[edit] I use Map - you could also use the object structures provided by json-lib instead.
Re: Your edit. Probably need to see your calling javascript. And probably I will suggest that you make sure you have both a success and an error handler. Can you debug/log to show that the method is being called in java ? Do your logs show anything ? This is usually some sort of error....