com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility Scala Examples
The following examples show how to use com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: JacksonMapperSpec.scala From squbs with Apache License 2.0 | 5 votes |
package org.squbs.marshallers.json import akka.actor.ActorSystem import akka.http.scaladsl.marshalling.Marshal import akka.http.scaladsl.model.{HttpEntity, MediaTypes, MessageEntity} import akka.http.scaladsl.unmarshalling.Unmarshal import akka.stream.ActorMaterializer import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility import com.fasterxml.jackson.annotation.PropertyAccessor import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.module.scala.DefaultScalaModule import org.scalatest.{AsyncFlatSpec, BeforeAndAfterAll, Matchers} import org.squbs.marshallers.json.TestData._ class JacksonMapperSpec extends AsyncFlatSpec with Matchers with BeforeAndAfterAll { import JacksonMapperSupport._ implicit val system = ActorSystem("JacksonMapperSpec") implicit val mat = ActorMaterializer() JacksonMapperSupport.setDefaultMapper(new ObjectMapper().registerModule(DefaultScalaModule)) it should "marshal and unmarshal standard case classes" in { val entity = HttpEntity(MediaTypes.`application/json`, fullTeamJson) Marshal(fullTeam).to[MessageEntity] map { _ shouldBe entity } Unmarshal(entity).to[Team] map { _ shouldBe fullTeam } } it should "marshal and unmarshal Scala non-case classes" in { val entity = HttpEntity(MediaTypes.`application/json`, fullTeamJson) Marshal(fullTeamNonCaseClass).to[MessageEntity] map { _ shouldBe entity } Unmarshal(entity).to[TeamNonCaseClass] map { _ shouldBe fullTeamNonCaseClass } } it should "marshal and unmarshal Scala class with Java Bean members" in { val entity = HttpEntity(MediaTypes.`application/json`, fullTeamJson) Marshal(fullTeamWithBeanMember).to[MessageEntity] map { _ shouldBe entity } Unmarshal(entity).to[TeamWithBeanMember] map { _ shouldBe fullTeamWithBeanMember } } it should "marshal and unmarshal Java Bean with case class members" in { val entity = HttpEntity(MediaTypes.`application/json`, fullTeamJson) Marshal(fullTeamWithCaseClassMember).to[MessageEntity] map { _ shouldBe entity } Unmarshal(entity).to[TeamBeanWithCaseClassMember] map { _ shouldBe fullTeamWithCaseClassMember } } it should "marshal and unmarshal Java Bean" in { val fieldMapper = new ObjectMapper().setVisibility(PropertyAccessor.FIELD, Visibility.ANY) .registerModule(DefaultScalaModule) JacksonMapperSupport.register[TeamWithPrivateMembers](fieldMapper) val entity = HttpEntity(MediaTypes.`application/json`, fullTeamJson) Marshal(fullTeamWithPrivateMembers).to[MessageEntity] map { _ shouldBe entity } Unmarshal(entity).to[TeamWithPrivateMembers] map { _ shouldBe fullTeamWithPrivateMembers } } it should "Marshal and unmarshal Jackson annotated Java subclasses" in { JacksonMapperSupport.register[PageData](new ObjectMapper) val entity = HttpEntity(MediaTypes.`application/json`, pageTestJson) Marshal(pageTest).to[MessageEntity] map { _ shouldBe entity } Unmarshal(entity).to[PageData] map { _ shouldBe pageTest } } }