fwbrasil / activate

Abandoned: Pluggable persistence in Scala
GNU Lesser General Public License v2.1
299 stars 46 forks source link

Objects as custom encoder #104

Closed vchuravy closed 10 years ago

vchuravy commented 10 years ago

Currently Encoders have to be implemented via classes:

class CEncoder extends Encoder[Category, String]
  def encode(value: Category) = value.name
  def decode(name: String) = Category.withName(name)

When I turn the class CEncoder into an object.

object CEncoder extends Encoder[Category, String]
  def encode(value: Category) = value.name
  def decode(name: String) = Category.withName(name)

I get the following Exception.

Caused by: java.lang.IllegalAccessException: Class net.fwbrasil.activate.entity.EntityValue$$anonfun$3 can not access a member of class models.postUtils.CEncoder$ with modifiers "private"
    at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:101) ~[na:1.8.0]
    at java.lang.Class.newInstance(Class.java:427) ~[na:1.8.0]
    at net.fwbrasil.activate.entity.EntityValue$$anonfun$3.apply(EntityValue.scala:155) ~[activate-core_2.10-1.5-M3.jar:1.5-M3]
    at net.fwbrasil.activate.entity.EntityValue$$anonfun$3.apply(EntityValue.scala:155) ~[activate-core_2.10-1.5-M3.jar:1.5-M3]
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244) ~[scala-library.jar:na]
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244) ~[scala-library.jar:na]

It would be nice to be able to implement Encoder via singleton objects and not just via classes