Skip to content

implicit conversions for attributes and values #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 16, 2016

Conversation

emanresusername
Copy link
Contributor

found myself doing

import org.zalando.jsonapi.model.Attribute
import org.zalando.jsonapi.model.JsonApiObject._

Attribute("name", StringValue("value"))

a lot, was nicer to just have this

import org.zalando.jsonapi.model.implicits.AttributeConversions._

"name" -> "value"

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 94.518% when pulling 9555391 on RavelLaw:issue/70 into 076b2f7 on zalando:master.

@codecov-io
Copy link

codecov-io commented Sep 8, 2016

Current coverage is 95.23% (diff: 100%)

Merging #71 into master will increase coverage by 0.19%

@@             master        #71   diff @@
==========================================
  Files            13         15     +2   
  Lines           444        462    +18   
  Methods         444        462    +18   
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits            422        440    +18   
  Misses           22         22          
  Partials          0          0          

Powered by Codecov. Last update 076b2f7...429102d

@lasomethingsomething
Copy link

Thanks for the contribution, @emanresusername. @zmeda, WDYT?

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 94.589% when pulling 429102d on RavelLaw:issue/70 into 076b2f7 on zalando:master.

@emanresusername
Copy link
Contributor Author

emanresusername commented Sep 15, 2016

added some optional conversions cause i found myself doing this pattern a lot too

val attributes = List(Attribute("name", StringValue(model.value)) ++
  model.optionalValue.map(value => Attribute("optionalName", StringValue(value)))

now can just do

val optionalAttribute: Option[Attribute] = "optionalName" -> model.optionalValue
val attributes = List(Attribute("name", StringValue(model.value)) ++ optionalAttribute

couldn't get it to work inline as

val attributes = List(Attribute("name", StringValue(model.value)) ++ 
  "optionalName" -> model.optionalValue

that'd be ideal if somebody knows how to get that syntax to work off the top of their head

@lasomethingsomething
Copy link

Thanks again, @emanresusername -- wanted to make sure we acknowledge your efforts to continue supporting our project.

@zmeda zmeda merged commit 65a489c into scala-jsonapi:master Sep 16, 2016
@zmeda
Copy link
Contributor

zmeda commented Sep 16, 2016

Thanks for PR, I'll publish new version soon.

@emanresusername emanresusername deleted the issue/70 branch September 16, 2016 20:23
@emanresusername
Copy link
Contributor Author

if you wanted to wait a little while on the new version, i'm gonna add a few more in for null, jsarrayvalue and jsobjectvalue that i just started hitting today 😅

@pettercastro
Copy link

pettercastro commented Sep 12, 2019

@zmeda @emanresusername Was the optional value removed? as I cannot find it here. I would like to not show some keys if their values are None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants