Scala bring value into implicit scope without naming it -


When using, I inherent scope for each domain type JsonFormat [A] to get The requirement is A that I want to serial.

to create a custom object with all implicits as recommended approach fields:

  object MyJsonProtocol expansion DefaultJsonProtocol {contained Val colorFormat = jsonFormat4 (color)} import MyJsonProtocol._  

My app is a great many domain types, some of which have a long name. I MyJsonProtocol is getting long and unreadable:

  object MyJsonProtocol extends DefaultJsonProtocol {... // There are many more built-Val someClassWithALongNameFormat = jsonFormat4 (SomeClassWithALongName) built-Val SomeClassWithAlongNameInnerFormat = jsonFormat4 (SomeClassWithALongNameInner) built-in Val someClassWithALongNameVariantBFormat = jsonFormat4 (SomeClassWithALongNameVariantB) ... // here many more}  

There are various problems with long val name:

    < Li> They feel nonsense (name is never read)
  • They make my lines very long
  • They introduce copy / paste risks that the name of the format will not match the format
  • They do not combine the RHS values, which hide the same pattern

Is there any way to bring any object under the name? Something like this would be much neater:

  object MyJsonProtocol extends DefaultJsonProtocol {... // many lies more on val _ = jsonFormat4 (SomeClassWithALongName) underlying val _ = jsonFormat4 (SomeClassWithALongNameInner) underlying Val _ = JsonFormat4 (SomeClassWithALongNameVariantB) ... here many more}  

... but many fields named Scala are not allowed "_".

Is there any way to bring these formats without giving names to all? What is another way to use spray-json which avoids this problem? Typically, I define type-class examples of fellow objects:

{Class} Fus ​​(case) Fu {vested val jsonFormatter = new JsonFormat [fu] {...}} case class bar (object bar) {vested val jsonFormatter = new JsonFormat [bar] {...}} < / Code>

I do not have to import anything because fellow objects are included in the underlying search scope by default, and the underlying members can all have the same name.


Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -