-
1. Re: Wildfly-8.0.0-CR1 Marshalling problem
darrenjones Jan 23, 2014 5:23 AM (in response to ybxiang.china)Is it anything to do with the Serializability of the containing class? By doing this (or the second example):
ArrayList<XOrder> orderbyList = new ArrayList<XOrder>(){
{
this.add(new XOrder("createDate",orderbyCreateDateAsc));
}
};
... an anonymous inner class is being created, which carries around with it a reference to its containing class. If you use a static inner class instead, does it work? Something like this (please forgive syntax errors!):
public class ContainingClass
{
private static class MyArrayList extends ArrayList<XOrder> {
public MyArrayList(Object orderByCreateDateAsc) {
this.add(new XOrder("createDate",orderbyCreateDateAsc));
}
}
}
...
Then try to construct and marshall MyArrayList...
-
2. Re: Wildfly-8.0.0-CR1 Marshalling problem
ybxiang.china Jan 23, 2014 5:59 AM (in response to darrenjones)Is it anything to do with the Serializability of the containing class?
~~~~~At first, I did NOT believe this can happen too. But this does happen, and I spent much time to find it out.
-
3. Re: Wildfly-8.0.0-CR1 Marshalling problem
dmlloyd Jan 23, 2014 8:56 AM (in response to ybxiang.china)This is interesting. What is the symptom of the failure? Is there an exception on deserialize?
-
4. Re: Wildfly-8.0.0-CR1 Marshalling problem
ybxiang.china Jan 25, 2014 11:05 PM (in response to dmlloyd)Caused by: java.io.NotSerializableException: com.ybxiang.nms.gui.platform.AlarmView
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:894)
at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1066)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1022)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:888)
at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1066)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1022)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:888)
at org.jboss.marshalling.AbstractObjectOutput.writeObject(AbstractObjectOutput.java:62)
at org.jboss.marshalling.AbstractMarshaller.writeObject(AbstractMarshaller.java:115)
at org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver.processInvocation(RemotingConnectionEJBReceiver.java:307)
... 61 more
Caused by: an exception which occurred:
in field this$0
in field orderby
in object com.ybxiang.jpa.query.api.XPager@179e873"
**************************************************************************** related classes ************************************************************************************
**************************************************************************** related classes ************************************************************************************
**************************************************************************** related classes ************************************************************************************
import java.io.Serializable;
import java.util.List;
public class XPager implements Serializable {
private static final long serialVersionUID = 1L;
public static final int DEFAULT_PAGESIZE = 50;//50
public static final int MINIMUM_PAGESIZE = 10;
public static final int MAXIMUM_PAGESIZE = 100;
public static final int MAX_PAGESIZE = 300;
public static final int PAGENUM_START = 1;
public static final String CRITERIA_FLAG = "?";
//public final String className;//to protect DB, please specify your classname in com.ybxiang.jpa.query.impl.PagerHelper.getResult(Class, EntityManager, XPager)
public int pageSize = DEFAULT_PAGESIZE;
public int pageNum = PAGENUM_START;
public String wherePattern;//Example: ((?)AND(?)) OR (?)
public List<ICriteria> conditionList;//its size equals the number of "?" in wherePattern
//
public List<XOrder> orderby;
}
import java.io.Serializable;
public class XOrder implements Serializable{
private static final long serialVersionUID = 1L;
public final String attributeName;
public final boolean asc;
public XOrder(String attributeName,boolean asc){
this.attributeName = attributeName;
this.asc = asc;
}
}
public interface ICriteria {
}
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
public class QueryResult implements Serializable {
private static final long serialVersionUID = 1L;
public int pageSize = XPager.DEFAULT_PAGESIZE;
public int pageNum = XPager.PAGENUM_START;
public int totalRecords = 0;
public int totalPages = XPager.PAGENUM_START;
@SuppressWarnings("rawtypes")
public List records = new ArrayList();
}
**************************************************************************** related ejb************************************************************************************
**************************************************************************** related ejb************************************************************************************
**************************************************************************** related ejb************************************************************************************
public interface ISecuredRemoteSession{
...
public QueryResult queryAfn0EErc(XPager pager);
...
}
@Remote(ISecuredRemoteSession.class)
@Stateless
public class SecuredRemoteSession implements ISecuredRemoteSession{
@PersistenceContext
protected EntityManager em;
...
@PermitAll()
public QueryResult queryAfn0EErc(XPager pager){
return PagerHelper.getResult(Afn0EErc.class,em, pager);
}
...
}
**************************************************************************** related client methods************************************************************************************
**************************************************************************** related client methods************************************************************************************
**************************************************************************** related client methods************************************************************************************
private final XPager pager = new XPager(); private void rebuildPager(){
... //method-1: WRONG! JBoss MARSHALLING tool can NOT serialize/de-serialize ArrayList<XOrder> orderbyList! /*ArrayList<XOrder> orderbyList = new ArrayList<XOrder>(){ { this.add(new XOrder("createDate",orderbyCreateDateAsc)); } };*/ //method-2: ArrayList<XOrder> orderbyList = new ArrayList<XOrder>(); orderbyList.add(new XOrder("createDate",orderbyCreateDateAsc)); // { pager.wherePattern = wherePattern; pager.conditionList = criteriaList; pager.orderby = orderbyList; } } private ISecuredRemoteSession getSessionWithSSL(){ return securedRemoteSessionProxy; }
public Object[] getElements(Object inputElement) {
QueryResult queryResult = this.getSessionWithSSL().queryAfn0EErc(pager); ... }
-
5. Re: Wildfly-8.0.0-CR1 Marshalling problem
darrenjones Jan 24, 2014 4:28 AM (in response to ybxiang.china)So the rebuildPager() method - could you clarify what class that is declared in? And is that Seralizable?
-
6. Re: Wildfly-8.0.0-CR1 Marshalling problem
ybxiang.china Jan 25, 2014 11:07 PM (in response to darrenjones)rebuildPager() is used to update XPager.
XPager is transfered to Wildfly8 through EJB Client.
I have updated above codes.
-
7. Re: Wildfly-8.0.0-CR1 Marshalling problem
darrenjones Jan 27, 2014 7:48 AM (in response to ybxiang.china)1 of 1 people found this helpfulI still think the location of the rebuildPager() method is key. Let's suppose that it's something like this (i.e. you have it in the AlarmView class):
public class AlarmView {
private final XPager pager = new XPager();
private void rebuildPager() {
ArrayList<XOrder> orderbyList = new ArrayList<XOrder>() {
{
this.add(new XOrder("createDate",orderbyCreateDateAsc));
};
pager.orderby = orderbyList;
}
}
The declaration "new ArrayList<XOrder>() { ... }" is not creating a plain ArrayList. Instead it is creating an anonymous inner class that is a subclass of ArrayList.
This anonymous inner class carries around with it a hidden reference called this$0 to the outer class, AlarmView. Therefore to be able to Serialize the anonymous inner class, the AlarmView class must also be Serializable.
This is likely to explain why "this$0" and "com.ybxiang.nms.gui.platform.AlarmView" appear in the stack trace you reported earlier.
-
8. Re: Wildfly-8.0.0-CR1 Marshalling problem
ybxiang.china Jan 27, 2014 7:33 PM (in response to darrenjones)I agree with you.