Serialization in GWT 2.5.1 - gwt

I've updated my project from GWT 2.4.0 to GWT 2.5.1 and suddenly a specific RPC serialization has stopped work (all other are still working).
I have this class:
public class StatusChangeMapEntity extends RecordStamp implements Serializable {
private HashMap<WFStatus, Pair<WFPhase, ArrayList<Pair<AppUser, Date>>>> map;
...
...
}
The exception message is:
Attempt to deserialize an object of type class Pair when an object of type class Slide is expected
The class Slide extends StatusChangeMapEntity and is the object that is being deserialized.
Any ideias how to solve this problems?
Thanks.

I've managed to solve this problem. Basically I've created a class extending the HashMap:
public class MapStatusChanges extends HashMap<WFStatus, Pair<WFPhase, ArrayList<Pair<AppUser, Date>>>> {
...
}
And then created a CustomSerializer to the MapStatusChanges.
It's not a generic solution, but it works until this problem is solved at GWT.
Hope this helps....

Related

Injection causes WELD-001408: Unsatisfied dependencies

I have a java EE web application in which a particular injection causes following error:
WELD-001408: Unsatisfied dependencies for type GenericDAO with qualifiers #Default
MyBean
#Stateless
public class MyBean extends CustomBean<Entity> {
...
}
CustomBean
public class CustomBean<T extends Serializable> implements Serializable {
#Inject
private GenericDAO<T> genericDAO;
}
GenericDAO
public abstract class GenericDAO<T extends Serializable> implements Serializable {
...
}
The issue appears only if a beans.xml is defined in the application. Deleting this, solves also the issue. In my case beans.xml is needed. Also when removing the GenericDAO<T> genericDAO; injection from the CustomBean, the error does not appear anymore. Also the rest of my injection in other classes, seem to work without any issue.
I've tried to solve that by creating an interface of GenericDAO and inject the interface instead. Also tried to with several anotations like #Local , #Dependent etc but i stumble upon different errors every time.

Java Object serialization in scala

Pardon me as I am new to Scala.
I have created a case class which encapsultes some information. One of the objects i want to take in for that is of JavaClass. As i am using in spark, i would need it to be serializable. How can i do that?
                              
Java class
public class Currency {
public Currency(final BigDecimal amount, final CurrencyUnit unit) {
//Doing Something
}
}
case class ReconEntity(inputCurrency : Currency, outputCurrency : Currency)
Using implicit i want to have my serialization code for Currency so that spark can work on ReconEntity.
Firstly, have you tried some RDD operations using your Currency and ReconEntity classes? Do you actually get an error? Spark is able to handle RDD operations with apparently non-serializable Scala classes as values, at least (you can try this in the spark-shell, though possibly this might require the Kryo serializer to be enabled).
Since you state that you don't own the Currency class, you can't add extends Serializable, which would be the simplest solution.
Another approach is to wrap the class with a serializable wrapper, as described in this article: Beating Serialization in Spark - example code copied here for convenience:
For simple classes, it is easiest to make a wrapper interface that
extends Serializable. This means that even though UnserializableObject
cannot be serialized we can pass in the following object without any
issue
public interface UnserializableWrapper extends Serializable {
public UnserializableObject create(String prm1, String prm2);
}
The object can then be passed into an RDD or Map function using the
following approach
UnserializableWrapper usw = new UnserializableWrapper() {
public UnserializableObject create(String prm1, String prm2) {
return new UnserializableObject(prm1,prm2);
} }
If the class is merely a data structure, without significant methods, then it might be easier to unpack its fields into your RDD types (in your case, ReconEntity) and discard the class itself.
If the class has methods that you need, then your other (ugly) option is to cut-and-paste code into a new serializable class or into helper functions in your Spark code.

Unity Container, Interface infinite loop

I need help with configuring MS Unity.
I have a class implementing an interface:
public class ProjectService : IProjectService
which works fine with this configuration:
_conainer.RegisterType<IProjectService, ProjectService>();
I another, caching, implementation, I need the first concrete type injected into the caching concrete type.
public class CachedProjectService : IProjectService
{
public CachedProjectService(IProjectService projectService, ICacheStorage cacheStorage)
{}
}
How can I configure Unity to return the caching version with the first implementation injected into it?
It's called decorators wiring that you can achieve like this :
_container.RegisterType<IProjectService, ProjectService>("innerService");
_container.RegisterType<IProjectService, CachedProjectService>(
new InjectionConstructor(
new ResolvedParameter<IProjectService>("innerService"),
new ResolvedParameter<ICacheStorage>()
));
Hope it helps

How to serialize instances of classes generated by DbMetal?

I noticed DbMetal generates classes that don't implement the ISerializable interface, nor are marked with DataContractAttribute. What is the easiest way of serializing such classes? Is there any DbMetal parameter that could help me?
try this:
[Serializable]
public partial class YourClassName { }
See Partial Classes for further details

Scala 2.12.4: Cannot access protected static Java method from another package anymore

I have java class with protected static method:
package parent;
public class Parent {
protected static void parentMethod() {
System.out.println("I'm in parent static method");
}
}
Before Scala 2.12.4 (2.12.3) I could call this method from another package like this:
package child
import parent.Parent
class Child extends Parent {
def childMethod = {
println("I'm in child method and calling parentMethod")
Parent.parentMethod()
}
}
But Scala 2.12.4 does not compile this code. I'm getting the error:
Error:(9, 12) method parentMethod in object Parent cannot be accessed
in object parent.Parent Access to protected method parentMethod not
permitted because prefix type parent.Parent.type does not conform to
object Child in package child where the access takes place
Parent.parentMethod()
This access pattern was very important for me because JOOQ code generation uses this.
What happened?
Nice catch, this is most likely a regression introduced by this PR, as part of a solution to this issue.
I've already opened a ticket for this that you can track. In the meanwhile, if this kind of access pattern is vital for your application, unfortunately I don't think you have much choice but to stick to Scala 2.12.3 for the time being.
Edit
The issue was already known and a fix has been already merged. As of the time of writing the patch is bound to be part of the 2.12.5 release.