gradeqert.blogg.se

Scala add jackson annotations to case class
Scala add jackson annotations to case class










scala add jackson annotations to case class
  1. #SCALA ADD JACKSON ANNOTATIONS TO CASE CLASS HOW TO#
  2. #SCALA ADD JACKSON ANNOTATIONS TO CASE CLASS CODE#

In our example, we are dealing only with strings but we could expand it to other type cases. In this case, the AST extractors work together to get a field of one case class. Literal and Constant are both AST extractors from Scala code. The method body says something like this: given a Tree Expression related to one field to obfuscate, if it matches with Literal(Constant(field: String)), then we are going to re-define it as a new term with the same name but with an obfuscated value. ToStringObfuscateImpl.obfuscateValue function within the replaceCaseClassSensitiveValues method. For each sensitive field we are going to replace them with a new obfuscated based * value, with a fixed length as we will soon see.For instance, "pinCode"), c.ee will be a tree with a structure similar to new ToStringObfuscate("password", "pinCode"), so unquoting it we can extract a parameters list ( Tree expression list as well).

scala add jackson annotations to case class

  • In c.ee we are receiving all of the sensitive fields specified in the annotation.
  • Therefore, the root project could be configured as follows:ĭef modifiedDeclaration(classDecl: ClassDef) = )Ĭase _ => c.abort(c.enclosingPosition, s" Match error with $tree")
  • Macro paradise: compiler plugin for Scala 2.10 and Scala 2.11 that adds new functionality such as quasiquotes and macro annotations to scala.reflect.
  • scala add jackson annotations to case class

    Scala Reflect: API that powers both compile-time metaprogramming (macros) and runtime metaprogramming (Java-style reflection) in Scala 2.10 and 2.11.To do so, we need some special dependencies related to macros: In the example we’re using, we can develop it in two different sbt modules: one with the macro implementation and the other with some test cases. With macros there are several ways to achieve it, but in this case we are going to annotate the case class with all the fields that must be obfuscated. We want to create a Macro that overrides the toString method and obfuscates all of those fields marked as sensitive in our case class. (You can learn more about macros in Scala Docs or on the Scala Macros website.) Let’s Configure the sample project At that point, the developer has access to compiler APIs so it’s possible to expand, generate, analyze and check your code.

    #SCALA ADD JACKSON ANNOTATIONS TO CASE CLASS CODE#

    Scala Macros are related with the code invoked by the compiler at compilation time. When we talk about macros, we’re referring to something that’s running at compilation time.

    #SCALA ADD JACKSON ANNOTATIONS TO CASE CLASS HOW TO#

    Here’s how to develop a ToStringObfuscate tag with Scala macros: Scala Macros Class TestWithObfuscation(username : String, password : String)












    Scala add jackson annotations to case class