com.fasterxml.jackson.annotation.JsonInclude Scala Examples
The following examples show how to use com.fasterxml.jackson.annotation.JsonInclude.
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: JacksonMessageWriter.scala From drizzle-spark with Apache License 2.0 | 6 votes |
package org.apache.spark.status.api.v1 import java.io.OutputStream import java.lang.annotation.Annotation import java.lang.reflect.Type import java.nio.charset.StandardCharsets import java.text.SimpleDateFormat import java.util.{Calendar, SimpleTimeZone} import javax.ws.rs.Produces import javax.ws.rs.core.{MediaType, MultivaluedMap} import javax.ws.rs.ext.{MessageBodyWriter, Provider} import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.databind.{ObjectMapper, SerializationFeature} @Provider @Produces(Array(MediaType.APPLICATION_JSON)) private[v1] class JacksonMessageWriter extends MessageBodyWriter[Object]{ val mapper = new ObjectMapper() { override def writeValueAsString(t: Any): String = { super.writeValueAsString(t) } } mapper.registerModule(com.fasterxml.jackson.module.scala.DefaultScalaModule) mapper.enable(SerializationFeature.INDENT_OUTPUT) mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL) mapper.setDateFormat(JacksonMessageWriter.makeISODateFormat) override def isWriteable( aClass: Class[_], `type`: Type, annotations: Array[Annotation], mediaType: MediaType): Boolean = { true } override def writeTo( t: Object, aClass: Class[_], `type`: Type, annotations: Array[Annotation], mediaType: MediaType, multivaluedMap: MultivaluedMap[String, AnyRef], outputStream: OutputStream): Unit = { t match { case ErrorWrapper(err) => outputStream.write(err.getBytes(StandardCharsets.UTF_8)) case _ => mapper.writeValue(outputStream, t) } } override def getSize( t: Object, aClass: Class[_], `type`: Type, annotations: Array[Annotation], mediaType: MediaType): Long = { -1L } } private[spark] object JacksonMessageWriter { def makeISODateFormat: SimpleDateFormat = { val iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'GMT'") val cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT")) iso8601.setCalendar(cal) iso8601 } }
Example 2
Source File: JacksonMessageWriter.scala From Spark-2.3.1 with Apache License 2.0 | 5 votes |
package org.apache.spark.status.api.v1 import java.io.OutputStream import java.lang.annotation.Annotation import java.lang.reflect.Type import java.nio.charset.StandardCharsets import java.text.SimpleDateFormat import java.util.{Calendar, Locale, SimpleTimeZone} import javax.ws.rs.Produces import javax.ws.rs.core.{MediaType, MultivaluedMap} import javax.ws.rs.ext.{MessageBodyWriter, Provider} import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.databind.{ObjectMapper, SerializationFeature} @Provider @Produces(Array(MediaType.APPLICATION_JSON)) private[v1] class JacksonMessageWriter extends MessageBodyWriter[Object]{ val mapper = new ObjectMapper() { override def writeValueAsString(t: Any): String = { super.writeValueAsString(t) } } mapper.registerModule(com.fasterxml.jackson.module.scala.DefaultScalaModule) mapper.enable(SerializationFeature.INDENT_OUTPUT) mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL) mapper.setDateFormat(JacksonMessageWriter.makeISODateFormat) override def isWriteable( aClass: Class[_], `type`: Type, annotations: Array[Annotation], mediaType: MediaType): Boolean = { true } override def writeTo( t: Object, aClass: Class[_], `type`: Type, annotations: Array[Annotation], mediaType: MediaType, multivaluedMap: MultivaluedMap[String, AnyRef], outputStream: OutputStream): Unit = { t match { case ErrorWrapper(err) => outputStream.write(err.getBytes(StandardCharsets.UTF_8)) case _ => mapper.writeValue(outputStream, t) } } override def getSize( t: Object, aClass: Class[_], `type`: Type, annotations: Array[Annotation], mediaType: MediaType): Long = { -1L } } private[spark] object JacksonMessageWriter { def makeISODateFormat: SimpleDateFormat = { val iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'GMT'", Locale.US) val cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT")) iso8601.setCalendar(cal) iso8601 } }
Example 3
Source File: ProjectDefaultJacksonMapper.scala From orders-aws with Apache License 2.0 | 5 votes |
package works.weave.socks.aws.orders import com.fasterxml.jackson.annotation.JsonAutoDetect import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.annotation.PropertyAccessor import com.fasterxml.jackson.databind.DeserializationFeature import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.SerializationFeature import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule import com.fasterxml.jackson.module.scala.DefaultScalaModule object ProjectDefaultJacksonMapper { def build() : ObjectMapper = { val mapper = new ObjectMapper() mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) mapper.setSerializationInclusion(JsonInclude.Include.ALWAYS) mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY) mapper.enable(SerializationFeature.INDENT_OUTPUT) mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) val javaTime : JavaTimeModule = new JavaTimeModule mapper.registerModule(javaTime) val scalaModule = new DefaultScalaModule() mapper.registerModule(scalaModule) mapper } }
Example 4
Source File: JacksonSupport.scala From stream-reactor with Apache License 2.0 | 5 votes |
package com.landoop.streamreactor.hive.it import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper} import com.fasterxml.jackson.module.scala.DefaultScalaModule import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper object JacksonSupport { val mapper: ObjectMapper with ScalaObjectMapper = new ObjectMapper with ScalaObjectMapper mapper.registerModule(DefaultScalaModule) mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL) mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false) mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true) mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true) mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true) }
Example 5
Source File: JacksonSupport.scala From stream-reactor with Apache License 2.0 | 5 votes |
package com.landoop.streamreactor.connect.hive import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper} import com.fasterxml.jackson.module.scala.DefaultScalaModule import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper object JacksonSupport { val mapper: ObjectMapper with ScalaObjectMapper = new ObjectMapper with ScalaObjectMapper mapper.registerModule(DefaultScalaModule) mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL) mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false) mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true) mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true) mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true) }
Example 6
Source File: JacksonSupport.scala From stream-reactor with Apache License 2.0 | 5 votes |
package com.landoop.streamreactor.hive.it import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper} import com.fasterxml.jackson.module.scala.DefaultScalaModule import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper object JacksonSupport { val mapper: ObjectMapper with ScalaObjectMapper = new ObjectMapper with ScalaObjectMapper mapper.registerModule(DefaultScalaModule) mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL) mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false) mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true) mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true) mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true) }
Example 7
Source File: JacksonSupport.scala From stream-reactor with Apache License 2.0 | 5 votes |
package com.landoop.streamreactor.connect.hive import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper} import com.fasterxml.jackson.module.scala.DefaultScalaModule import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper object JacksonSupport { val mapper: ObjectMapper with ScalaObjectMapper = new ObjectMapper with ScalaObjectMapper mapper.registerModule(DefaultScalaModule) mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL) mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false) mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true) mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true) mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true) }
Example 8
Source File: JsonUtils.scala From asura with MIT License | 5 votes |
package asura.common.util import java.io.InputStream import java.text.SimpleDateFormat import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.core.`type`.TypeReference import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper} import com.fasterxml.jackson.module.scala.DefaultScalaModule import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper object JsonUtils extends JsonUtils { val mapper: ObjectMapper with ScalaObjectMapper = new ObjectMapper() with ScalaObjectMapper mapper.registerModule(DefaultScalaModule) mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")) mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL) mapper.configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true) mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false) mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true) mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true) mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true) } trait JsonUtils { val mapper: ObjectMapper def stringify(obj: AnyRef): String = { mapper.writeValueAsString(obj) } def parse[T <: AnyRef](content: String, c: Class[T]): T = { mapper.readValue(content, c) } def parse[T <: AnyRef](input: InputStream, c: Class[T]): T = { mapper.readValue(input, c) } def parse[T <: AnyRef](content: String, typeReference: TypeReference[T]): T = { mapper.readValue(content, typeReference) } }
Example 9
Source File: JavaJsonUtils.scala From asura with MIT License | 5 votes |
package asura.common.util import java.text.SimpleDateFormat import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper} object JavaJsonUtils extends JsonUtils { val mapper: ObjectMapper = new ObjectMapper() mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")) mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL) mapper.configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true) mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false) mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true) mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true) mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true) }
Example 10
Source File: JacksonMessageWriter.scala From BigDatalog with Apache License 2.0 | 5 votes |
package org.apache.spark.status.api.v1 import java.io.OutputStream import java.lang.annotation.Annotation import java.lang.reflect.Type import java.text.SimpleDateFormat import java.util.{Calendar, SimpleTimeZone} import javax.ws.rs.Produces import javax.ws.rs.core.{MediaType, MultivaluedMap} import javax.ws.rs.ext.{MessageBodyWriter, Provider} import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.databind.{ObjectMapper, SerializationFeature} @Provider @Produces(Array(MediaType.APPLICATION_JSON)) private[v1] class JacksonMessageWriter extends MessageBodyWriter[Object]{ val mapper = new ObjectMapper() { override def writeValueAsString(t: Any): String = { super.writeValueAsString(t) } } mapper.registerModule(com.fasterxml.jackson.module.scala.DefaultScalaModule) mapper.enable(SerializationFeature.INDENT_OUTPUT) mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL) mapper.setDateFormat(JacksonMessageWriter.makeISODateFormat) override def isWriteable( aClass: Class[_], `type`: Type, annotations: Array[Annotation], mediaType: MediaType): Boolean = { true } override def writeTo( t: Object, aClass: Class[_], `type`: Type, annotations: Array[Annotation], mediaType: MediaType, multivaluedMap: MultivaluedMap[String, AnyRef], outputStream: OutputStream): Unit = { t match { case ErrorWrapper(err) => outputStream.write(err.getBytes("utf-8")) case _ => mapper.writeValue(outputStream, t) } } override def getSize( t: Object, aClass: Class[_], `type`: Type, annotations: Array[Annotation], mediaType: MediaType): Long = { -1L } } private[spark] object JacksonMessageWriter { def makeISODateFormat: SimpleDateFormat = { val iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'GMT'") val cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT")) iso8601.setCalendar(cal) iso8601 } }
Example 11
Source File: JacksonSupport.scala From pulsar4s with Apache License 2.0 | 5 votes |
package com.sksamuel.pulsar4s.jackson import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.databind.module.SimpleModule import com.fasterxml.jackson.databind.ser.std.NumberSerializers import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper} import com.fasterxml.jackson.module.scala.DefaultScalaModule import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper object JacksonSupport { val mapper: ObjectMapper with ScalaObjectMapper = new ObjectMapper with ScalaObjectMapper mapper.registerModule(DefaultScalaModule) mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL) mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false) mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true) mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true) mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true) val module = new SimpleModule module.addSerializer(new NumberSerializers.DoubleSerializer(classOf[Double])) }
Example 12
Source File: KVUtils.scala From Spark-2.3.1 with Apache License 2.0 | 5 votes |
package org.apache.spark.status import java.io.File import scala.annotation.meta.getter import scala.collection.JavaConverters._ import scala.language.implicitConversions import scala.reflect.{classTag, ClassTag} import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.module.scala.DefaultScalaModule import org.apache.spark.internal.Logging import org.apache.spark.util.kvstore._ private[spark] object KVUtils extends Logging { def viewToSeq[T]( view: KVStoreView[T], max: Int) (filter: T => Boolean): Seq[T] = { val iter = view.closeableIterator() try { iter.asScala.filter(filter).take(max).toList } finally { iter.close() } } private[spark] class MetadataMismatchException extends Exception }
Example 13
Source File: JacksonMessageWriter.scala From spark1.52 with Apache License 2.0 | 5 votes |
package org.apache.spark.status.api.v1 import java.io.OutputStream import java.lang.annotation.Annotation import java.lang.reflect.Type import java.text.SimpleDateFormat import java.util.{Calendar, SimpleTimeZone} import javax.ws.rs.Produces import javax.ws.rs.core.{MediaType, MultivaluedMap} import javax.ws.rs.ext.{MessageBodyWriter, Provider} import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.databind.{ObjectMapper, SerializationFeature} @Provider @Produces(Array(MediaType.APPLICATION_JSON)) private[v1] class JacksonMessageWriter extends MessageBodyWriter[Object]{ val mapper = new ObjectMapper() { override def writeValueAsString(t: Any): String = { super.writeValueAsString(t) } } mapper.registerModule(com.fasterxml.jackson.module.scala.DefaultScalaModule) mapper.enable(SerializationFeature.INDENT_OUTPUT) mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL) mapper.setDateFormat(JacksonMessageWriter.makeISODateFormat) override def isWriteable( aClass: Class[_], `type`: Type, annotations: Array[Annotation], mediaType: MediaType): Boolean = { true } override def writeTo( t: Object, aClass: Class[_], `type`: Type, annotations: Array[Annotation], mediaType: MediaType, multivaluedMap: MultivaluedMap[String, AnyRef], outputStream: OutputStream): Unit = { t match { case ErrorWrapper(err) => outputStream.write(err.getBytes("utf-8")) case _ => mapper.writeValue(outputStream, t) } } override def getSize( t: Object, aClass: Class[_], `type`: Type, annotations: Array[Annotation], mediaType: MediaType): Long = { -1L } } private[spark] object JacksonMessageWriter { def makeISODateFormat: SimpleDateFormat = { val iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'GMT'") val cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT")) iso8601.setCalendar(cal) iso8601 } }
Example 14
Source File: JacksonMessageWriter.scala From iolap with Apache License 2.0 | 5 votes |
package org.apache.spark.status.api.v1 import java.io.OutputStream import java.lang.annotation.Annotation import java.lang.reflect.Type import java.text.SimpleDateFormat import java.util.{Calendar, SimpleTimeZone} import javax.ws.rs.Produces import javax.ws.rs.core.{MediaType, MultivaluedMap} import javax.ws.rs.ext.{MessageBodyWriter, Provider} import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.databind.{ObjectMapper, SerializationFeature} @Provider @Produces(Array(MediaType.APPLICATION_JSON)) private[v1] class JacksonMessageWriter extends MessageBodyWriter[Object]{ val mapper = new ObjectMapper() { override def writeValueAsString(t: Any): String = { super.writeValueAsString(t) } } mapper.registerModule(com.fasterxml.jackson.module.scala.DefaultScalaModule) mapper.enable(SerializationFeature.INDENT_OUTPUT) mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL) mapper.setDateFormat(JacksonMessageWriter.makeISODateFormat) override def isWriteable( aClass: Class[_], `type`: Type, annotations: Array[Annotation], mediaType: MediaType): Boolean = { true } override def writeTo( t: Object, aClass: Class[_], `type`: Type, annotations: Array[Annotation], mediaType: MediaType, multivaluedMap: MultivaluedMap[String, AnyRef], outputStream: OutputStream): Unit = { t match { case ErrorWrapper(err) => outputStream.write(err.getBytes("utf-8")) case _ => mapper.writeValue(outputStream, t) } } override def getSize( t: Object, aClass: Class[_], `type`: Type, annotations: Array[Annotation], mediaType: MediaType): Long = { -1L } } private[spark] object JacksonMessageWriter { def makeISODateFormat: SimpleDateFormat = { val iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'GMT'") val cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT")) iso8601.setCalendar(cal) iso8601 } }
Example 15
Source File: JacksonMessageWriter.scala From multi-tenancy-spark with Apache License 2.0 | 5 votes |
package org.apache.spark.status.api.v1 import java.io.OutputStream import java.lang.annotation.Annotation import java.lang.reflect.Type import java.nio.charset.StandardCharsets import java.text.SimpleDateFormat import java.util.{Calendar, Locale, SimpleTimeZone} import javax.ws.rs.Produces import javax.ws.rs.core.{MediaType, MultivaluedMap} import javax.ws.rs.ext.{MessageBodyWriter, Provider} import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.databind.{ObjectMapper, SerializationFeature} @Provider @Produces(Array(MediaType.APPLICATION_JSON)) private[v1] class JacksonMessageWriter extends MessageBodyWriter[Object]{ val mapper = new ObjectMapper() { override def writeValueAsString(t: Any): String = { super.writeValueAsString(t) } } mapper.registerModule(com.fasterxml.jackson.module.scala.DefaultScalaModule) mapper.enable(SerializationFeature.INDENT_OUTPUT) mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL) mapper.setDateFormat(JacksonMessageWriter.makeISODateFormat) override def isWriteable( aClass: Class[_], `type`: Type, annotations: Array[Annotation], mediaType: MediaType): Boolean = { true } override def writeTo( t: Object, aClass: Class[_], `type`: Type, annotations: Array[Annotation], mediaType: MediaType, multivaluedMap: MultivaluedMap[String, AnyRef], outputStream: OutputStream): Unit = { t match { case ErrorWrapper(err) => outputStream.write(err.getBytes(StandardCharsets.UTF_8)) case _ => mapper.writeValue(outputStream, t) } } override def getSize( t: Object, aClass: Class[_], `type`: Type, annotations: Array[Annotation], mediaType: MediaType): Long = { -1L } } private[spark] object JacksonMessageWriter { def makeISODateFormat: SimpleDateFormat = { val iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'GMT'", Locale.US) val cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT")) iso8601.setCalendar(cal) iso8601 } }
Example 16
Source File: JacksonMessageWriter.scala From sparkoscope with Apache License 2.0 | 5 votes |
package org.apache.spark.status.api.v1 import java.io.OutputStream import java.lang.annotation.Annotation import java.lang.reflect.Type import java.nio.charset.StandardCharsets import java.text.SimpleDateFormat import java.util.{Calendar, Locale, SimpleTimeZone} import javax.ws.rs.Produces import javax.ws.rs.core.{MediaType, MultivaluedMap} import javax.ws.rs.ext.{MessageBodyWriter, Provider} import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.databind.{ObjectMapper, SerializationFeature} @Provider @Produces(Array(MediaType.APPLICATION_JSON)) private[v1] class JacksonMessageWriter extends MessageBodyWriter[Object]{ val mapper = new ObjectMapper() { override def writeValueAsString(t: Any): String = { super.writeValueAsString(t) } } mapper.registerModule(com.fasterxml.jackson.module.scala.DefaultScalaModule) mapper.enable(SerializationFeature.INDENT_OUTPUT) mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL) mapper.setDateFormat(JacksonMessageWriter.makeISODateFormat) override def isWriteable( aClass: Class[_], `type`: Type, annotations: Array[Annotation], mediaType: MediaType): Boolean = { true } override def writeTo( t: Object, aClass: Class[_], `type`: Type, annotations: Array[Annotation], mediaType: MediaType, multivaluedMap: MultivaluedMap[String, AnyRef], outputStream: OutputStream): Unit = { t match { case ErrorWrapper(err) => outputStream.write(err.getBytes(StandardCharsets.UTF_8)) case _ => mapper.writeValue(outputStream, t) } } override def getSize( t: Object, aClass: Class[_], `type`: Type, annotations: Array[Annotation], mediaType: MediaType): Long = { -1L } } private[spark] object JacksonMessageWriter { def makeISODateFormat: SimpleDateFormat = { val iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'GMT'", Locale.US) val cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT")) iso8601.setCalendar(cal) iso8601 } }
Example 17
Source File: UserImpl.scala From meteorite-core with Apache License 2.0 | 5 votes |
package bi.meteorite.objects import javax.persistence._ import bi.meteorite.core.api.objects.{MeteoriteRole, MeteoriteUser} import com.fasterxml.jackson.annotation.{JsonInclude, JsonManagedReference} @Entity(name = "USERS") @Table(name = "USERS") class UserImpl extends MeteoriteUser { @Id @Column @TableGenerator(name = "EVENT_GEN", table = "SEQUENCES", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_NUMBER", pkColumnValue = "SEQUENCE", allocationSize = 1) @GeneratedValue(strategy = GenerationType.TABLE, generator = "EVENT_GEN") private var id: Long = _ @Column(length = 100) private var username: String = _ @Column(length = 100) private var password: String = _ @JsonInclude(JsonInclude.Include.NON_EMPTY) @OneToMany(mappedBy = "userid", fetch = FetchType.LAZY, cascade = Array(CascadeType.ALL)) @JsonManagedReference private val roles: java.util.List[RoleImpl] = new java.util.ArrayList[RoleImpl]() @Column private var orgId: Int = _ @Column private var email: String = _ def getUsername: String = { username } def setUsername(username: String) { this.username = username } def getPassword: String = { password } def setPassword(password: String) { this.password = password } //@OneToMany(fetch = FetchType.EAGER, mappedBy = "user") def getRoles: java.util.List[MeteoriteRole] = { val l = new java.util.ArrayList[MeteoriteRole]() import scala.collection.JavaConversions._ for (role <- roles) { l.add(role) } l } def setRoles(roles: java.util.List[MeteoriteRole]) { import scala.collection.JavaConversions._ if(roles != null) { for (r <- roles) { this.roles.add(r.asInstanceOf[RoleImpl]) } } } def getEmail: String = { email } def setEmail(email: String) { this.email = email } def getId: Long = { id } def setId(id: Long) { this.id = id } def getOrgId: Int = { orgId } def setOrgId(orgId: Int) { this.orgId = orgId } }
Example 18
Source File: JacksonSupport.scala From eel-sdk with Apache License 2.0 | 5 votes |
package io.eels.util import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper} import com.fasterxml.jackson.module.scala.DefaultScalaModule import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper object JacksonSupport { val mapper: ObjectMapper with ScalaObjectMapper = new ObjectMapper with ScalaObjectMapper mapper.registerModule(DefaultScalaModule) mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL) mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false) mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true) mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true) mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true) }
Example 19
Source File: TestCaseClass.scala From daf with BSD 3-Clause "New" or "Revised" License | 5 votes |
import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.annotation.JsonInclude.Include import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.module.scala.DefaultScalaModule import de.zalando.play.controllers.WriterFactories import it.gov.daf.catalogmanager.{ConversionField, MetaCatalog, StdSchema} import play.api.libs.json._ object TestCaseClass extends App{ //@JsonInclude(JsonInclude.Include.NON_ABSENT) case class Pippo (ogg1: Option[String], ogg2: String, ogg3: Option[Pluto]) //case class Pippo (ogg1: Option[String], ogg2: String) //case class Pluto (prop1: String, prop2: String, prop3: List[String]) case class Pluto (prop1: String, prop2: String) val pippo = Pippo(Some("ciao"), "", None) //val pippo = Pippo(Some("ciao"), "ciao2") def jacksonMapper(mimeType: String): ObjectMapper = { //noinspection ScalaStyle assert(mimeType != null) val factory = WriterFactories.factories(mimeType) val mapper = new ObjectMapper(factory) mapper.setSerializationInclusion(JsonInclude.Include.NON_ABSENT) mapper.registerModule(DefaultScalaModule) mapper } val json = jacksonMapper("blabla").writeValueAsString(pippo) //val json = "{\"ogg1\":\"ciao\",\"ogg2\":\"ciao2\"}" println(json) //implicit val plutoReads = Json.reads[Pluto] //implicit val pippoReads = Json.reads[Pippo] //implicit val plutoReads = Json.reads[Option[Pluto]] }
Example 20
Source File: JacksonScalaProvider.scala From daf-semantics with Apache License 2.0 | 5 votes |
package it.almawave.kb.http.providers import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider import com.fasterxml.jackson.databind.ObjectMapper import javax.ws.rs.ext.Provider import javax.ws.rs.Produces import com.fasterxml.jackson.module.scala.DefaultScalaModule import javax.ws.rs.core.MediaType import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.databind.SerializationFeature import com.fasterxml.jackson.databind.DeserializationFeature import javax.ws.rs.ext.ContextResolver import com.fasterxml.jackson.databind.JsonSerializer import com.fasterxml.jackson.core.JsonGenerator import com.fasterxml.jackson.databind.SerializerProvider import java.lang.Double import java.lang.Boolean @Provider @Produces(Array(MediaType.APPLICATION_JSON)) class JacksonScalaProvider extends JacksonJaxbJsonProvider with ContextResolver[ObjectMapper] { println("\n\nregistered " + this.getClass) val mapper = new ObjectMapper() mapper .registerModule(DefaultScalaModule) .setSerializationInclusion(JsonInclude.Include.ALWAYS) .configure(SerializationFeature.INDENT_OUTPUT, true) .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true) .configure(SerializationFeature.WRITE_NULL_MAP_VALUES, true) .configure(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED, true) .configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, true) .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) .configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true) .configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true) .configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true) // .setVisibility(JsonMethod.FIELD, Visibility.ANY); .getSerializerProvider.setNullValueSerializer(new JsonSerializer[Object] { def serialize(obj: Object, gen: JsonGenerator, provider: SerializerProvider) { obj match { case bool: Boolean => gen.writeBoolean(false) case number: Integer => gen.writeNumber(0) case number: Double => gen.writeNumber(0.0D) case text: String => gen.writeString("") case _ => gen.writeString("") } } }) super.setMapper(mapper) override def getContext(klasses: Class[_]): ObjectMapper = mapper }