Giter Site home page Giter Site logo

Comments (5)

advorkovyy avatar advorkovyy commented on May 25, 2024

try scalabeans. it has also bean builder, you provide it with property values you have and it figures how to create new bean instance with them: either via constructor args or by assigning property values or by combination of both.

from jackson-module-scala.

christophercurrie avatar christophercurrie commented on May 25, 2024

Thanks for the tip; I'd been exploring the ScalaSigParser in scalap, but the API in scalabeans looks much friendlier

from jackson-module-scala.

cowtowncoder avatar cowtowncoder commented on May 25, 2024

What do auto-generated properties look like? Since it is possible to figure out which classes are case classes, it should be possible to construct scala-specific AnnotationIntrospector to change definition of how property names are introspected for fields. This also applies to implicit get/set methods (set ones end with '='?).

from jackson-module-scala.

christophercurrie avatar christophercurrie commented on May 25, 2024

That's the approach I'd tried to take with scalap, but the API wasn't nearly as convenient. I've managed to get a very simple test case working with just constructor arguments. I'm going to take a stab at extending it for read/write properties outside the constructor before committing.

from jackson-module-scala.

advorkovyy avatar advorkovyy commented on May 25, 2024

Properties have auto-generated getter with the same name as property and setter with "_$eq" suffix. Setters are generated only for mutable properties (var). Variables (val/var) are in the same symbol space as methods in Scala (in contrast with Java), ie there cannot be both variable and method with the same name. When using Java reflection method can be distinguished from val by looking at the presence of private field with the same name.

There are some other interesting situations like "synthetic" properties (having explicit getter/setter in Scala code), constructor parameters, properties derived from superclasses. They might have slight variations of described pattern.

Another peculiarity is that since Scala 2.9 in some situations Scala types are seen from Java reflection as just Object. For example, Option[Int] becomes Option<Object> in Java reflection. So, using ScalaSig is inevitable to get the right property type.

This all applies to all Scala classes, of course, not only to case classes.

from jackson-module-scala.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.