com.fasterxml.jackson.core.JsonGenerator Scala Examples
The following examples show how to use com.fasterxml.jackson.core.JsonGenerator.
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: TypedJsonSerializer.scala From milan with Apache License 2.0 | 5 votes |
package com.amazon.milan.serialization import com.fasterxml.jackson.core.JsonGenerator import com.fasterxml.jackson.databind.{JsonSerializer, SerializerProvider} class TypedJsonSerializer[T <: TypeInfoProvider] extends JsonSerializer[T] { override def serialize(value: T, jsonGenerator: JsonGenerator, serializerProvider: SerializerProvider): Unit = { val typeName = value.getJsonTypeName try { jsonGenerator.writeStartObject() jsonGenerator.writeStringField("_type", typeName) jsonGenerator.writeObject(value) jsonGenerator.writeEndObject() } catch { case ex: Throwable => throw new JsonSerializationException(s"Error serializing object of type $typeName.", ex) } } } class JsonSerializationException(message: String, cause: Throwable) extends Exception(message, cause) { }
Example 2
Source File: CirceJsonSerializer.scala From circe-jackson with Apache License 2.0 | 5 votes |
package io.circe.jackson import com.fasterxml.jackson.core.JsonGenerator import com.fasterxml.jackson.databind.{ JsonSerializer, SerializerProvider } import io.circe.{ Json, JsonBigDecimal, JsonBiggerDecimal, JsonDecimal, JsonDouble, JsonFloat, JsonLong } private[jackson] final object CirceJsonSerializer extends JsonSerializer[Json] { import java.math.{ BigDecimal => JBigDecimal, BigInteger } import com.fasterxml.jackson.databind.node.{ BigIntegerNode, DecimalNode } override final def serialize( value: Json, json: JsonGenerator, provider: SerializerProvider ): Unit = value match { case Json.JNumber(v) => v match { case JsonLong(x) => json.writeNumber(x) case JsonDouble(x) => json.writeNumber(x) case JsonFloat(x) => json.writeNumber(x) case JsonDecimal(x) => json.writeString(x) case JsonBiggerDecimal(_, x) => json.writeString(x) case JsonBigDecimal(x) => // Workaround #3784: Same behaviour as if JsonGenerator were // configured with WRITE_BIGDECIMAL_AS_PLAIN, but forced as this // configuration is ignored when called from ObjectMapper.valueToTree val raw = x.stripTrailingZeros.toPlainString if (raw contains ".") json.writeTree(new DecimalNode(new JBigDecimal(raw))) else json.writeTree(new BigIntegerNode(new BigInteger(raw))) } case Json.JString(v) => json.writeString(v) case Json.JBoolean(v) => json.writeBoolean(v) case Json.JArray(elements) => { json.writeStartArray() elements.foreach(t => serialize(t, json, provider)) json.writeEndArray() } case Json.JObject(values) => { json.writeStartObject() values.toList.foreach { t => json.writeFieldName(t._1) serialize(t._2, json, provider) } json.writeEndObject() } case Json.JNull => json.writeNull() } }
Example 3
Source File: CustomJson.scala From Waves with MIT License | 5 votes |
package com.wavesplatform.http import java.io.IOException import akka.http.scaladsl.model.{MediaRange, MediaType} import akka.http.scaladsl.model.MediaTypes.`application/json` import com.fasterxml.jackson.core.io.SegmentedStringWriter import com.fasterxml.jackson.core.util.BufferRecyclers import com.fasterxml.jackson.core.{JsonGenerator, JsonProcessingException} import com.fasterxml.jackson.databind.module.SimpleModule import com.fasterxml.jackson.databind.{JsonMappingException, JsonSerializer, ObjectMapper, SerializerProvider} import play.api.libs.json._ object NumberAsStringSerializer extends JsonSerializer[JsValue] { private val fieldNamesToTranslate = Set( "amount", "available", "balance", "buyMatcherFee", "currentReward", "desiredReward", "effective", "fee", "feeAmount", "generating", "in", "matcherFee", "minIncrement", "minSponsoredAssetFee", "out", "price", "quantity", "regular", "reward", "sellMatcherFee", "sponsorBalance", "totalAmount", "totalFee", "totalWavesAmount", "value" ) override def serialize(value: JsValue, json: JsonGenerator, provider: SerializerProvider): Unit = { value match { case JsNumber(v) => json.writeNumber(v.bigDecimal) case JsString(v) => json.writeString(v) case JsBoolean(v) => json.writeBoolean(v) case JsArray(elements) => json.writeStartArray() elements.foreach { t => serialize(t, json, provider) } json.writeEndArray() case JsObject(values) => json.writeStartObject() values.foreach { case (name, JsNumber(v)) if fieldNamesToTranslate(name) => json.writeStringField(name, v.bigDecimal.toPlainString) case (name, jsv) => json.writeFieldName(name) serialize(jsv, json, provider) } json.writeEndObject() case JsNull => json.writeNull() } } } object CustomJson { val jsonWithNumbersAsStrings: MediaType.WithFixedCharset = `application/json`.withParams(Map("large-significand-format" -> "string")) def acceptsNumbersAsStrings(mr: MediaRange): Boolean = mr match { case MediaRange.One(`jsonWithNumbersAsStrings`, _) => true case _ => false } private lazy val mapper = (new ObjectMapper) .registerModule(new SimpleModule("WavesJson").addSerializer(classOf[JsValue], NumberAsStringSerializer)) .configure(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN, true) def writeValueAsString(value: JsValue): String = { val sw = new SegmentedStringWriter(BufferRecyclers.getBufferRecycler) try mapper.writeValue(sw, value) catch { case e: JsonProcessingException => throw e case e: IOException => // shouldn't really happen, but is declared as possibility so: throw JsonMappingException.fromUnexpectedIOE(e) } sw.getAndClear } }
Example 4
Source File: Program.scala From fusion-data with Apache License 2.0 | 5 votes |
package mass.model.job import com.fasterxml.jackson.annotation.JsonValue import com.fasterxml.jackson.core.{ JsonGenerator, JsonParser } import com.fasterxml.jackson.databind.{ DeserializationContext, SerializerProvider } import com.fasterxml.jackson.databind.annotation.{ JsonDeserialize, JsonSerialize } import com.fasterxml.jackson.databind.deser.std.StdDeserializer import com.fasterxml.jackson.databind.ser.std.StdSerializer import helloscala.common.data.StringValueName @JsonSerialize(using = classOf[Program.EnumSer]) @JsonDeserialize(using = classOf[Program.EnumDeser]) sealed abstract class Program(@JsonValue val value: String, val name: String) { def toValueName: StringValueName = StringValueName(value, name) } object Program { case object SCALA extends Program("scala", "Scala") case object JAVA extends Program("java", "Java") case object PYTHON extends Program("python", "Python") case object SH extends Program("sh", "SH") case object SQL extends Program("sql", "SQL") case object JS extends Program("js", "Javascript") val values = Vector(SCALA, JAVA, PYTHON, SH, SQL, JS) def fromValue(value: String): Program = optionFromValue(value).getOrElse( throw new NoSuchElementException(s"Program.values by name not found, it is $value.")) def optionFromValue(value: String): Option[Program] = { val v = value.toLowerCase() values.find(_.value == v) } def fromName(name: String): Program = optionFromName(name).getOrElse(throw new NoSuchElementException(s"Program.values by name not found, it is $name.")) def optionFromName(name: String): Option[Program] = { val n = name.toLowerCase() values.find(_.name == n) } class EnumSer extends StdSerializer[Program](classOf[Program]) { override def serialize(value: Program, gen: JsonGenerator, provider: SerializerProvider): Unit = gen.writeString(value.value) } class EnumDeser extends StdDeserializer[Program](classOf[Program]) { override def deserialize(p: JsonParser, ctxt: DeserializationContext): Program = Program.fromValue(p.getValueAsString) } }
Example 5
Source File: TriggerType.scala From fusion-data with Apache License 2.0 | 5 votes |
package mass.model.job import com.fasterxml.jackson.core.{ JsonGenerator, JsonParser } import com.fasterxml.jackson.databind.annotation.{ JsonDeserialize, JsonSerialize } import com.fasterxml.jackson.databind.deser.std.StdDeserializer import com.fasterxml.jackson.databind.ser.std.StdSerializer import com.fasterxml.jackson.databind.{ DeserializationContext, SerializerProvider } import helloscala.common.util.{ IEnumTrait, IEnumTraitCompanion } @JsonSerialize(using = classOf[TriggerType.EnumSer]) @JsonDeserialize(using = classOf[TriggerType.EnumDeser]) sealed abstract class TriggerType extends IEnumTrait[String] { override val value: String = name } object TriggerType extends IEnumTraitCompanion[String] { self => override type Value = TriggerType case object SIMPLE extends TriggerType case object CRON extends TriggerType case object EVENT extends TriggerType override val values = Vector(CRON, EVENT, SIMPLE) override def optionFromValue(value: String): Option[TriggerType] = super.optionFromValue(value.toUpperCase()) class EnumSer extends StdSerializer[TriggerType](classOf[TriggerType]) { override def serialize(value: TriggerType, gen: JsonGenerator, provider: SerializerProvider): Unit = gen.writeString(value.value) } class EnumDeser extends StdDeserializer[TriggerType](classOf[TriggerType]) { override def deserialize(p: JsonParser, ctxt: DeserializationContext): TriggerType = TriggerType.fromValue(p.getValueAsString.toUpperCase()) } }
Example 6
Source File: JsonLifter.scala From diffy with GNU Affero General Public License v3.0 | 5 votes |
package ai.diffy.lifter import com.fasterxml.jackson.core.{JsonGenerator, JsonToken} import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.StdSerializer import com.fasterxml.jackson.databind.{JsonNode, ObjectMapper, SerializerProvider} import com.fasterxml.jackson.module.scala.DefaultScalaModule import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper import com.twitter.util.Try import scala.collection.JavaConversions._ import scala.language.postfixOps import scala.reflect.runtime.universe.runtimeMirror import scala.tools.reflect.ToolBox import scala.util.control.NoStackTrace object JsonLifter { @JsonSerialize(using = classOf[JsonNullSerializer]) object JsonNull object JsonParseError extends Exception with NoStackTrace val toolbox = runtimeMirror(getClass.getClassLoader).mkToolBox() val Mapper = new ObjectMapper with ScalaObjectMapper Mapper.registerModule(DefaultScalaModule) def apply(obj: Any): JsonNode = Mapper.valueToTree(obj) def lift(node: JsonNode): Any = node.asToken match { case JsonToken.START_ARRAY => node.elements.toSeq.map { element => lift(element) } case JsonToken.START_OBJECT => { val fields = node.fieldNames.toSet if (fields.exists{ field => Try(toolbox.parse(s"object ${field}123")).isThrow}) { node.fields map {field => (field.getKey -> lift(field.getValue))} toMap } else { FieldMap( node.fields map {field => (field.getKey -> lift(field.getValue))} toMap ) } } case JsonToken.VALUE_FALSE => false case JsonToken.VALUE_NULL => JsonNull case JsonToken.VALUE_NUMBER_FLOAT => node.asDouble case JsonToken.VALUE_NUMBER_INT => node.asLong case JsonToken.VALUE_TRUE => true case JsonToken.VALUE_STRING => node.textValue case _ => throw JsonParseError } def decode(json: String): JsonNode = Mapper.readTree(json) def encode(item: Any): String = Mapper.writer.writeValueAsString(item) } class JsonNullSerializer(clazz: Class[Any]) extends StdSerializer[Any](clazz) { def this() { this(null) } override def serialize(t: Any, jsonGenerator: JsonGenerator, serializerProvider: SerializerProvider): Unit = { jsonGenerator.writeNull() } }
Example 7
Source File: SqlStatementSerialization.scala From NSDb with Apache License 2.0 | 5 votes |
package io.radicalbit.nsdb.common.statement import com.fasterxml.jackson.core.{JsonGenerator, JsonParser} import com.fasterxml.jackson.databind.{DeserializationContext, SerializerProvider} import com.fasterxml.jackson.databind.deser.std.StdDeserializer import com.fasterxml.jackson.databind.ser.std.StdSerializer object SqlStatementSerialization { object ComparisonOperatorSerialization { class ComparisonOperatorJsonSerializer extends StdSerializer[ComparisonOperator](classOf[ComparisonOperator]) { override def serialize(value: ComparisonOperator, gen: JsonGenerator, provider: SerializerProvider): Unit = gen.writeString(value.toString) } class ComparisonOperatorJsonDeserializer extends StdDeserializer[ComparisonOperator](classOf[ComparisonOperator]) { override def deserialize(p: JsonParser, ctxt: DeserializationContext): ComparisonOperator = { p.getText match { case "GreaterThanOperator" => GreaterThanOperator case "GreaterOrEqualToOperator" => GreaterOrEqualToOperator case "LessThanOperator" => LessThanOperator case "LessOrEqualToOperator" => LessOrEqualToOperator } } } } object AggregationSerialization { class AggregationJsonSerializer extends StdSerializer[Aggregation](classOf[Aggregation]) { override def serialize(value: Aggregation, gen: JsonGenerator, provider: SerializerProvider): Unit = gen.writeString(value.toString) } class AggregationJsonDeserializer extends StdDeserializer[Aggregation](classOf[Aggregation]) { override def deserialize(p: JsonParser, ctxt: DeserializationContext): Aggregation = { p.getText match { case "CountAggregation" => CountAggregation case "MaxAggregation" => MaxAggregation case "MinAggregation" => MinAggregation case "SumAggregation" => SumAggregation case "FirstAggregation" => FirstAggregation case "LastAggregation" => LastAggregation case "AvgAggregation" => AvgAggregation } } } } object LogicalOperatorSerialization { class LogicalOperatorJsonSerializer extends StdSerializer[LogicalOperator](classOf[LogicalOperator]) { override def serialize(value: LogicalOperator, gen: JsonGenerator, provider: SerializerProvider): Unit = gen.writeString(value.toString) } class LogicalOperatorJsonDeserializer extends StdDeserializer[LogicalOperator](classOf[LogicalOperator]) { override def deserialize(p: JsonParser, ctxt: DeserializationContext): LogicalOperator = { p.getText match { case "NotOperator" => NotOperator case "AndOperator" => AndOperator case "OrOperator" => OrOperator } } } } }
Example 8
Source File: FieldClassType.scala From NSDb with Apache License 2.0 | 5 votes |
package io.radicalbit.nsdb.common.protocol import com.fasterxml.jackson.core.{JsonGenerator, JsonParser} import com.fasterxml.jackson.databind.annotation.{JsonDeserialize, JsonSerialize} import com.fasterxml.jackson.databind.{DeserializationContext, SerializerProvider} import com.fasterxml.jackson.databind.deser.std.StdDeserializer import com.fasterxml.jackson.databind.ser.std.StdSerializer @JsonSerialize(using = classOf[FieldClassTypeJsonSerializer]) @JsonDeserialize(using = classOf[FieldClassTypeJsonDeserializer]) sealed trait FieldClassType case object TimestampFieldType extends FieldClassType case object ValueFieldType extends FieldClassType case object DimensionFieldType extends FieldClassType case object TagFieldType extends FieldClassType class FieldClassTypeJsonSerializer extends StdSerializer[FieldClassType](classOf[FieldClassType]) { override def serialize(value: FieldClassType, gen: JsonGenerator, provider: SerializerProvider): Unit = gen.writeString(value.toString) } class FieldClassTypeJsonDeserializer extends StdDeserializer[FieldClassType](classOf[FieldClassType]) { override def deserialize(p: JsonParser, ctxt: DeserializationContext): FieldClassType = { p.getText match { case "TimestampFieldType" => TimestampFieldType case "ValueFieldType" => ValueFieldType case "DimensionFieldType" => DimensionFieldType case "TagFieldType" => TagFieldType } } }
Example 9
Source File: EnumEntrySerializer.scala From TransmogrifAI with BSD 3-Clause "New" or "Revised" License | 5 votes |
package com.salesforce.op.utils.json import com.fasterxml.jackson.core.{JsonGenerator, JsonParser} import com.fasterxml.jackson.databind.deser.std.StdDeserializer import com.fasterxml.jackson.databind.ser.std.StdSerializer import com.fasterxml.jackson.databind.{DeserializationContext, SerializerProvider} import enumeratum.{Enum, EnumEntry} import org.json4s.CustomSerializer import org.json4s.JsonAST.JString import scala.reflect.ClassTag def jackson[A <: EnumEntry: ClassTag](enum: Enum[A]): SerDes[A] = { val klazz = implicitly[ClassTag[A]].runtimeClass.asInstanceOf[Class[A]] val ser = new StdSerializer[A](klazz) { override def serialize(value: A, gen: JsonGenerator, provider: SerializerProvider): Unit = { gen.writeString(value.entryName) } } val des = new StdDeserializer[A](klazz) { override def deserialize(p: JsonParser, ctxt: DeserializationContext): A = { enum.withNameInsensitive(p.getValueAsString) } } new SerDes[A](klazz, ser, des) } }
Example 10
Source File: ObjectMapping.scala From ncdbg with BSD 3-Clause "New" or "Revised" License | 5 votes |
package com.programmaticallyspeaking.ncd.infra import com.fasterxml.jackson.annotation.JsonInclude.Include import com.fasterxml.jackson.core.JsonGenerator import com.fasterxml.jackson.databind._ import com.fasterxml.jackson.databind.ser.Serializers import com.fasterxml.jackson.databind.ser.std.StdSerializer import com.fasterxml.jackson.module.scala.{DefaultScalaModule, JacksonModule} import com.programmaticallyspeaking.ncd.chrome.domains.Runtime.RemoteObject import scala.reflect.ClassTag private class RemoteObjectSerializer extends StdSerializer[RemoteObject](classOf[RemoteObject]) { override def serialize(value: RemoteObject, gen: JsonGenerator, provider: SerializerProvider): Unit = { assert(value.productArity == 8, "Expected RemoteObject to have 8 product elements, but it has " + value.productArity) gen.writeStartObject() // (`type`: String, subtype: String, className: String, description: String, value: Any, unserializableValue: String, objectId: String) write(value, value.`type`, "type", gen) write(value, value.subtype, "subtype", gen) write(value, value.className, "className", gen) write(value, value.description, "description", gen) write(value, value.value, "value", gen) write(value, value.unserializableValue, "unserializableValue", gen) write(value, value.objectId, "objectId", gen) write(value, value.preview, "preview", gen) gen.writeEndObject() } private def write(remoteObject: RemoteObject, value: Any, field: String, gen: JsonGenerator): Unit = value match { case Some(x) => gen.writeObjectField(field, x) case None => // omit case other => gen.writeObjectField(field, other) } } private object RemoteObjectSerializerResolver extends Serializers.Base { private val REMOTE_OBJECT = classOf[RemoteObject] override def findSerializer(config: SerializationConfig, `type`: JavaType, beanDesc: BeanDescription): JsonSerializer[_] = { if (!REMOTE_OBJECT.isAssignableFrom(`type`.getRawClass)) null else new RemoteObjectSerializer() } } trait RemoteObjectModule extends JacksonModule { this += (_ addSerializers RemoteObjectSerializerResolver) } object ObjectMapping { private val mapper = new ObjectMapper() mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) mapper.setSerializationInclusion(Include.NON_ABSENT) mapper.registerModule(new DefaultScalaModule with RemoteObjectModule) def fromJson[R <: Any : ClassTag](json: String): R = { val clazz = implicitly[ClassTag[R]].runtimeClass fromJson(json, clazz).asInstanceOf[R] } def fromJson[R](json: String, clazz: Class[R]): R = mapper.readValue(json, clazz) def toJson[A](obj: A) = mapper.writeValueAsString(obj) def fromMap[R](map: Map[String, Any], clazz: Class[R]): R = mapper.convertValue(map, clazz) }
Example 11
Source File: SmileJson4sScalaModule.scala From spark-druid-olap with Apache License 2.0 | 5 votes |
package org.json4s.jackson.sparklinedata import com.fasterxml.jackson.core.JsonGenerator import com.fasterxml.jackson.databind.Module.SetupContext import com.fasterxml.jackson.databind.{BeanDescription, JavaType, SerializationConfig} import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.ser.Serializers import org.json4s.jackson.{JValueDeserializerResolver, Json4sScalaModule} import org.json4s._ class SmileJson4sScalaModule extends Json4sScalaModule { override def setupModule(ctxt: SetupContext) { ctxt.addSerializers(JValueSerializerResolver) ctxt.addDeserializers(JValueDeserializerResolver) } } object SmileJson4sScalaModule extends SmileJson4sScalaModule { } private object JValueSerializerResolver extends Serializers.Base { private val JVALUE = classOf[JValue] override def findSerializer(config: SerializationConfig, theType: JavaType, beanDesc: BeanDescription) = { if (!JVALUE.isAssignableFrom(theType.getRawClass)) null else new JValueSerializer } } class JValueSerializer extends org.json4s.jackson.JValueSerializer { import JValueSerializer.isInt override def serialize(value: JValue, json: JsonGenerator, provider: SerializerProvider) { value match { case JInt(v) if isInt(v) => json.writeNumber(v.intValue) case _ => super.serialize(value, json, provider) } } } object JValueSerializer { val intMax : BigInt = Int.MaxValue val intMin : BigInt = Int.MinValue def isInt(i : BigInt) : Boolean = i != null && !( i.compare(intMax) > 0 || i.compare(intMin) < 0) }
Example 12
Source File: JacksonTokenWriter.scala From tethys with Apache License 2.0 | 5 votes |
package tethys.jackson import com.fasterxml.jackson.core.JsonGenerator import tethys.writers.tokens.TokenWriter class JacksonTokenWriter(jsonGenerator: JsonGenerator) extends TokenWriter { override def writeArrayStart(): JacksonTokenWriter.this.type = { jsonGenerator.writeStartArray() this } override def writeArrayEnd(): JacksonTokenWriter.this.type = { jsonGenerator.writeEndArray() this } override def writeObjectStart(): JacksonTokenWriter.this.type = { jsonGenerator.writeStartObject() this } override def writeObjectEnd(): JacksonTokenWriter.this.type = { jsonGenerator.writeEndObject() this } override def writeFieldName(name: String): JacksonTokenWriter.this.type = { jsonGenerator.writeFieldName(name) this } override def writeString(v: String): JacksonTokenWriter.this.type = { jsonGenerator.writeString(v) this } override def writeNumber(v: Short): JacksonTokenWriter.this.type = { jsonGenerator.writeNumber(v) this } override def writeNumber(v: Int): JacksonTokenWriter.this.type = { jsonGenerator.writeNumber(v) this } override def writeNumber(v: Long): JacksonTokenWriter.this.type = { jsonGenerator.writeNumber(v) this } override def writeNumber(v: BigInt): JacksonTokenWriter.this.type = { jsonGenerator.writeNumber(v.bigInteger) this } override def writeNumber(v: Double): JacksonTokenWriter.this.type = { jsonGenerator.writeNumber(v) this } override def writeNumber(v: Float): JacksonTokenWriter.this.type = { jsonGenerator.writeNumber(v) this } override def writeNumber(v: BigDecimal): JacksonTokenWriter.this.type = { jsonGenerator.writeNumber(v.bigDecimal) this } override def writeRawJson(json: String): JacksonTokenWriter.this.type = { jsonGenerator.writeRawValue(json) this } override def writeBoolean(v: Boolean): JacksonTokenWriter.this.type = { jsonGenerator.writeBoolean(v) this } override def writeNull(): JacksonTokenWriter.this.type = { jsonGenerator.writeNull() this } override def close(): Unit = jsonGenerator.close() override def flush(): Unit = jsonGenerator.flush() }
Example 13
Source File: StringOfEscapedCharsBenchmark.scala From jsoniter-scala with MIT License | 5 votes |
package com.github.plokhotnyuk.jsoniter_scala.benchmark import java.lang.Character._ import java.nio.charset.StandardCharsets.UTF_8 import com.fasterxml.jackson.core.JsonGenerator import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.module.scala.ScalaObjectMapper import com.github.plokhotnyuk.jsoniter_scala.benchmark.JacksonSerDesers._ import org.openjdk.jmh.annotations.{Param, Setup} class StringOfEscapedCharsBenchmark extends CommonParams { @Param(Array("1", "10", "100", "1000", "10000", "100000", "1000000")) var size: Int = 1000 var obj: String = _ var jsonString: String = _ var jsonString2: String = _ var jsonBytes: Array[Byte] = _ var preallocatedBuf: Array[Byte] = _ @Setup def setup(): Unit = { obj = { val cs = new Array[Char](size) var i = 0 var j = 1 while (i < cs.length) { cs(i) = { var ch: Char = 0 while ({ ch = (j * 1498724053).toChar j += 1 ch < 128 || isSurrogate(ch) }) () ch } i += 1 } new String(cs) } jsonString = "\"" + obj.map(ch => f"\\u$ch%04x").mkString + "\"" jsonString2 = "\"" + obj.map(ch => f"\\u$ch%04X").mkString + "\"" jsonBytes = jsonString.getBytes(UTF_8) preallocatedBuf = new Array[Byte](jsonBytes.length + 100) } }
Example 14
Source File: Kind.scala From incubator-livy with Apache License 2.0 | 5 votes |
package org.apache.livy.sessions import com.fasterxml.jackson.core.{JsonGenerator, JsonParser, JsonToken} import com.fasterxml.jackson.databind._ import com.fasterxml.jackson.databind.module.SimpleModule sealed abstract class Kind(val name: String) { override def toString: String = name } object Spark extends Kind("spark") object PySpark extends Kind("pyspark") object SparkR extends Kind("sparkr") object Shared extends Kind("shared") object SQL extends Kind("sql") object Kind { def apply(kind: String): Kind = kind match { case "spark" | "scala" => Spark case "pyspark" | "python" => PySpark case "sparkr" | "r" => SparkR case "shared" => Shared case "sql" => SQL case other => throw new IllegalArgumentException(s"Invalid kind: $other") } } class SessionKindModule extends SimpleModule("SessionKind") { addSerializer(classOf[Kind], new JsonSerializer[Kind]() { override def serialize(value: Kind, jgen: JsonGenerator, provider: SerializerProvider): Unit = { jgen.writeString(value.toString) } }) addDeserializer(classOf[Kind], new JsonDeserializer[Kind]() { override def deserialize(jp: JsonParser, ctxt: DeserializationContext): Kind = { require(jp.getCurrentToken() == JsonToken.VALUE_STRING, "Kind should be a string.") Kind(jp.getText()) } }) }
Example 15
Source File: CustomJson.scala From matcher with MIT License | 5 votes |
package com.wavesplatform.dex.api.http.json import java.io.IOException import akka.http.scaladsl.model.MediaType import akka.http.scaladsl.model.MediaTypes.`application/json` import com.fasterxml.jackson.core.io.SegmentedStringWriter import com.fasterxml.jackson.core.util.BufferRecyclers import com.fasterxml.jackson.core.{JsonGenerator, JsonProcessingException} import com.fasterxml.jackson.databind.module.SimpleModule import com.fasterxml.jackson.databind.{JsonMappingException, JsonSerializer, ObjectMapper, SerializerProvider} import play.api.libs.json._ object NumberAsStringSerializer extends JsonSerializer[JsValue] { private val fieldNamesToTranslate = Set( "amount", "available", "balance", "buyMatcherFee", "currentReward", "desiredReward", "effective", "fee", "feeAmount", "generating", "in", "matcherFee", "minIncrement", "minSponsoredAssetFee", "out", "price", "quantity", "regular", "reward", "sellMatcherFee", "sponsorBalance", "totalAmount", "totalFee", "totalWavesAmount", "value" ) override def serialize(value: JsValue, json: JsonGenerator, provider: SerializerProvider): Unit = { value match { case JsNumber(v) => json.writeNumber(v.bigDecimal) case JsString(v) => json.writeString(v) case JsBoolean(v) => json.writeBoolean(v) case JsArray(elements) => json.writeStartArray() elements.foreach { t => serialize(t, json, provider) } json.writeEndArray() case JsObject(values) => json.writeStartObject() values.foreach { case (name, JsNumber(v)) if fieldNamesToTranslate(name) => json.writeStringField(name, v.bigDecimal.toPlainString) case (name, jsv) => json.writeFieldName(name) serialize(jsv, json, provider) } json.writeEndObject() case JsNull => json.writeNull() } } } object CustomJson { val jsonWithNumbersAsStrings: MediaType.WithFixedCharset = `application/json`.withParams(Map("large-significand-format" -> "string")) private lazy val mapper = (new ObjectMapper) .registerModule(new SimpleModule("WavesJson").addSerializer(classOf[JsValue], NumberAsStringSerializer)) .configure(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN, true) def writeValueAsString(value: JsValue): String = { val sw = new SegmentedStringWriter(BufferRecyclers.getBufferRecycler) try mapper.writeValue(sw, value) catch { case e: JsonProcessingException => throw e case e: IOException => // shouldn't really happen, but is declared as possibility so: throw JsonMappingException.fromUnexpectedIOE(e) } sw.getAndClear } }
Example 16
Source File: ColumnDateTimeFormats.scala From milan with Apache License 2.0 | 5 votes |
package com.amazon.milan.dataformats import java.time.Instant import java.time.format.DateTimeFormatter import com.fasterxml.jackson.core.JsonGenerator import com.fasterxml.jackson.databind.module.SimpleModule import com.fasterxml.jackson.databind.{JsonSerializer, SerializerProvider} class ColumnDateTimeFormatsInstantSerializer(dateTimeFormats: Map[String, DateTimeFormatter]) extends JsonSerializer[Instant] { override def serialize(value: Instant, jsonGenerator: JsonGenerator, serializerProvider: SerializerProvider): Unit = { val contextName = jsonGenerator.getOutputContext.getCurrentName val dateTimeFormatter = this.dateTimeFormats.get(contextName) match { case Some(formatter) => formatter case None => DateTimeFormatter.ISO_INSTANT } jsonGenerator.writeString(dateTimeFormatter.format(value)) } }
Example 17
Source File: GenericTypedJsonSerializer.scala From milan with Apache License 2.0 | 5 votes |
package com.amazon.milan.serialization import com.fasterxml.jackson.core.JsonGenerator import com.fasterxml.jackson.databind.{JsonSerializer, SerializerProvider} import com.typesafe.scalalogging.Logger import org.slf4j.LoggerFactory class GenericTypedJsonSerializer[T <: GenericTypeInfoProvider] extends JsonSerializer[T] { private val logger = Logger(LoggerFactory.getLogger(getClass)) override def serialize(value: T, jsonGenerator: JsonGenerator, serializerProvider: SerializerProvider): Unit = { val typeName = value.getTypeName val genericArgs = value.getGenericArguments logger.info(s"Serializing type '$typeName[${genericArgs.map(_.fullName).mkString(", ")}]'.") jsonGenerator.writeStartObject() jsonGenerator.writeStringField("_type", value.getTypeName) jsonGenerator.writeObjectField("_genericArgs", value.getGenericArguments) jsonGenerator.writeObject(value) jsonGenerator.writeEndObject() } }
Example 18
Source File: CheckJsString.scala From swagger-check with MIT License | 5 votes |
package de.leanovate.swaggercheck.shrinkable import com.fasterxml.jackson.core.JsonGenerator import de.leanovate.swaggercheck.schema.adapter.NodeAdapter import org.scalacheck.Shrink case class CheckJsString( formatted: Boolean, minLength: Option[Int], value: String ) extends CheckJsValue { override def asText(default: String): String = value override def generate(json: JsonGenerator): Unit = json.writeString(value) override def shrink: Stream[CheckJsString] = if (formatted) Stream.empty else minLength match { case Some(len) if value.length <= len => Stream.empty case Some(len) => Shrink.shrink(value).filter(_.length >= len).map(CheckJsString(formatted, minLength, _)) case None => Shrink.shrink(value).map(CheckJsString(formatted, minLength, _)) } } object CheckJsString { def unformatted(value:String) = CheckJsString(formatted = false, None, value) def formatted(value: String) = CheckJsString(formatted = true, None, value) implicit lazy val shrinkJsValue: Shrink[CheckJsString] = Shrink[CheckJsString](_.shrink) }
Example 19
Source File: SourceModuleSupport.scala From exodus with MIT License | 5 votes |
package com.wix.bazel.migrator.analyze import java.io.IOException import com.fasterxml.jackson.core.{JsonGenerator, JsonParser, JsonToken} import com.fasterxml.jackson.databind._ import com.fasterxml.jackson.databind.module.SimpleModule import com.wix.bazel.migrator.model.SourceModule class SourceModuleSupportingModule(modules: Set[SourceModule]) extends SimpleModule { addDeserializer(classOf[SourceModule], new SourceModuleSupportingDeserializer(modules)) addSerializer(classOf[SourceModule], new SourceModuleSupportingSerializer) } class SourceModuleSupportingSerializer extends JsonSerializer[SourceModule] { @throws[IOException] def serialize(value: SourceModule, gen: JsonGenerator, serializers: SerializerProvider): Unit = value match { case null => gen.writeNull() case _ => gen.writeString(value.relativePathFromMonoRepoRoot) } } class SourceModuleSupportingDeserializer(modules: Set[SourceModule]) extends JsonDeserializer[SourceModule] { @throws[IOException] def deserialize(p: JsonParser, ctxt: DeserializationContext): SourceModule = p.getCurrentToken match { case JsonToken.VALUE_NULL => null case JsonToken.VALUE_STRING => { val relativePath = p.readValueAs(classOf[String]) modules.find(_.relativePathFromMonoRepoRoot == relativePath) .getOrElse(throw ctxt.weirdStringException(relativePath, classOf[SourceModule], s"could not find module with relative path for $relativePath")) } case token => throw ctxt.wrongTokenException(p, JsonToken.VALUE_STRING, s"The value of a module must be a string and currently is $token") } }
Example 20
Source File: RelativePathSupport.scala From exodus with MIT License | 5 votes |
package com.wix.bazel.migrator.analyze import java.io.IOException import java.nio.file.{Path, Paths} import com.fasterxml.jackson.core.{JsonGenerator, JsonParser, JsonToken} import com.fasterxml.jackson.databind._ import com.fasterxml.jackson.databind.module.SimpleModule class RelativePathSupportingModule extends SimpleModule { addDeserializer(classOf[Path], new RelativePathSupportingDeserializer) addSerializer(classOf[Path], new RelativePathSupportingSerializer) } class RelativePathSupportingSerializer extends JsonSerializer[Path] { @throws[IOException] def serialize(value: Path, gen: JsonGenerator, serializers: SerializerProvider): Unit = value match { case null => gen.writeNull() case _ => gen.writeString(value.toString) } } class RelativePathSupportingDeserializer extends JsonDeserializer[Path] { @throws[IOException] def deserialize(p: JsonParser, ctxt: DeserializationContext): Path = p.getCurrentToken match { case JsonToken.VALUE_NULL => null case JsonToken.VALUE_STRING => Paths.get(p.readValueAs(classOf[String])) case _ => throw ctxt.wrongTokenException(p, JsonToken.VALUE_STRING, "The value of a java.nio.file.Path must be a string") } }
Example 21
Source File: ThirdPartyOverridesReader.scala From exodus with MIT License | 5 votes |
package com.wixpress.build.bazel import com.fasterxml.jackson.core.JsonGenerator import com.fasterxml.jackson.databind._ import com.fasterxml.jackson.databind.module.SimpleModule import com.fasterxml.jackson.module.scala.DefaultScalaModule object ThirdPartyOverridesReader { def from(json: String): ThirdPartyOverrides = { mapper.readValue(json, classOf[ThirdPartyOverrides]) } def mapper: ObjectMapper = { val objectMapper = new ObjectMapper() .registerModule(DefaultScalaModule) objectMapper.registerModule(overrideCoordinatesKeyModule(objectMapper)) objectMapper } private def overrideCoordinatesKeyModule(mapper: ObjectMapper): Module = new SimpleModule() .addKeyDeserializer(classOf[OverrideCoordinates], new OverrideCoordinatesKeyDeserializer(mapper)) .addKeySerializer(classOf[OverrideCoordinates], new OverrideCoordinatesKeySerializer(mapper)) private class OverrideCoordinatesKeySerializer(mapper: ObjectMapper) extends JsonSerializer[OverrideCoordinates] { override def serialize(value: OverrideCoordinates, gen: JsonGenerator, serializers: SerializerProvider): Unit = gen.writeFieldName(value.groupId + ":" + value.artifactId) } private class OverrideCoordinatesKeyDeserializer(mapper: ObjectMapper) extends KeyDeserializer { override def deserializeKey(key: String, ctxt: DeserializationContext): AnyRef = key.split(':') match { case Array(groupId, artifactId) => OverrideCoordinates(groupId, artifactId) case _ => throw new IllegalArgumentException(s"OverrideCoordinates key should be in form of groupId:artifactId, got $key") } } }
Example 22
Source File: JsonMerkleRootsSerializer.scala From Sidechains-SDK with MIT License | 5 votes |
package com.horizen.serialization import com.fasterxml.jackson.core.JsonGenerator import com.fasterxml.jackson.databind import com.fasterxml.jackson.databind.SerializerProvider import com.horizen.utils.{ByteArrayWrapper, BytesUtils} import scala.collection.mutable.Map import scala.collection.mutable.Iterable class JsonMerkleRootsSerializer extends databind.JsonSerializer[Option[Map[ByteArrayWrapper, Array[Byte]]]] { override def serialize(t: Option[Map[ByteArrayWrapper, Array[Byte]]], jsonGenerator: JsonGenerator, serializerProvider: SerializerProvider): Unit = { if(t.isDefined){ var listOfPair : Iterable[Pair] = t.get.map(k => Pair(BytesUtils.toHexString(k._1.data), BytesUtils.toHexString(k._2))) jsonGenerator.writeObject(listOfPair) }else{ jsonGenerator.writeStartArray() jsonGenerator.writeEndArray() } } } private case class Pair(key : String, value : String)
Example 23
Source File: JsonHorizenPublicKeyHashSerializer.scala From Sidechains-SDK with MIT License | 5 votes |
package com.horizen.serialization import com.fasterxml.jackson.core.JsonGenerator import com.fasterxml.jackson.databind.{JsonSerializer, SerializerProvider} import com.horizen.params.TestNetParams import com.horizen.utils.BytesUtils // Serialize public key hash bytes as Horizen standard public key address base58 string class JsonHorizenPublicKeyHashSerializer extends JsonSerializer[Array[Byte]] { override def serialize(publicKeyHash: Array[Byte], jsonGenerator: JsonGenerator, serializerProvider: SerializerProvider): Unit = { jsonGenerator.writeString(BytesUtils.toHorizenPublicKeyAddress(publicKeyHash, JsonHorizenPublicKeyHashSerializer.testNetParams)) } } object JsonHorizenPublicKeyHashSerializer { // TODO: fix this: we should serialize Horizen public key hash depend on Network type // In MainNet we will display Horizen public key address wrongly! // Unfortunately we have no easy way to access Network params from here. private val testNetParams = TestNetParams() }
Example 24
Source File: JsonMerklePathSerializer.scala From Sidechains-SDK with MIT License | 5 votes |
package com.horizen.serialization import com.fasterxml.jackson.core.JsonGenerator import com.fasterxml.jackson.databind import com.fasterxml.jackson.databind.SerializerProvider import com.horizen.utils.{BytesUtils, MerklePath} import scala.collection.JavaConverters._ class JsonMerklePathSerializer extends databind.JsonSerializer[MerklePath] { override def serialize(t: MerklePath, jsonGenerator: JsonGenerator, serializerProvider: SerializerProvider): Unit = { var listOfPair : Iterable[Pair] = t.merklePathList.asScala.map(k => Pair(k.getKey.toString, BytesUtils.toHexString(k.getValue))) jsonGenerator.writeObject(listOfPair) } } class JsonMerklePathOptionSerializer extends databind.JsonSerializer[Option[MerklePath]] { override def serialize(t: Option[MerklePath], jsonGenerator: JsonGenerator, serializerProvider: SerializerProvider): Unit = { if(t.isDefined){ new JsonMerklePathSerializer().serialize(t.get, jsonGenerator, serializerProvider) }else{ jsonGenerator.writeStartArray() jsonGenerator.writeEndArray() } } }
Example 25
Source File: JsonConverter.scala From scala-serialization with MIT License | 5 votes |
package com.komanov.serialization.converters import java.time.Instant import com.fasterxml.jackson.core.{JsonGenerator, JsonParser, Version} import com.fasterxml.jackson.databind.Module.SetupContext import com.fasterxml.jackson.databind._ import com.fasterxml.jackson.databind.module.{SimpleDeserializers, SimpleSerializers} import com.fasterxml.jackson.module.scala.DefaultScalaModule import com.komanov.serialization.domain.{Site, SiteEvent, SiteEventData} object JsonConverter extends MyConverter { private object InstantModule extends Module { override def getModuleName: String = "Instant" override def setupModule(context: SetupContext): Unit = { val serializers = new SimpleSerializers serializers.addSerializer(classOf[Instant], new JsonSerializer[Instant] { override def serialize(value: Instant, gen: JsonGenerator, serializers: SerializerProvider): Unit = { gen.writeNumber(value.toEpochMilli) } }) val deserializers = new SimpleDeserializers deserializers.addDeserializer(classOf[Instant], new JsonDeserializer[Instant] { override def deserialize(p: JsonParser, ctxt: DeserializationContext): Instant = { Instant.ofEpochMilli(p.getLongValue) } }) context.addSerializers(serializers) context.addDeserializers(deserializers) } override def version(): Version = new Version(1, 0, 0, "RELEASE", "group", "artifact") } private val objectMapper = { val om = new ObjectMapper() om.registerModule(new DefaultScalaModule) om.registerModule(InstantModule) om } private val siteReader: ObjectReader = objectMapper.readerFor(classOf[Site]) private val siteWriter: ObjectWriter = objectMapper.writerFor(classOf[Site]) override def toByteArray(site: Site): Array[Byte] = { siteWriter.writeValueAsBytes(site) } override def fromByteArray(bytes: Array[Byte]): Site = { siteReader.readValue(bytes) } override def toByteArray(event: SiteEvent): Array[Byte] = { objectMapper.writeValueAsBytes(event) } override def siteEventFromByteArray(clazz: Class[_], bytes: Array[Byte]): SiteEvent = { objectMapper.readValue(bytes, clazz).asInstanceOf[SiteEvent] } }
Example 26
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 }
Example 27
Source File: HttpOrderBook.scala From matcher with MIT License | 5 votes |
package com.wavesplatform.dex.api.http.entities import com.fasterxml.jackson.core.{JsonGenerator, JsonParser} import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.deser.std.StdDeserializer import com.fasterxml.jackson.databind.module.SimpleModule import com.fasterxml.jackson.databind.ser.std.StdSerializer import com.fasterxml.jackson.databind.{DeserializationContext, JsonNode, ObjectMapper, SerializerProvider} import com.fasterxml.jackson.module.scala.DefaultScalaModule import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper import com.wavesplatform.dex.domain.asset.Asset.{IssuedAsset, Waves} import com.wavesplatform.dex.domain.asset.{Asset, AssetPair} import com.wavesplatform.dex.domain.bytes.ByteStr import com.wavesplatform.dex.domain.model.Denormalization import com.wavesplatform.dex.model.LevelAgg @JsonSerialize(using = classOf[HttpOrderBook.Serializer]) case class HttpOrderBook(timestamp: Long, pair: AssetPair, bids: Seq[LevelAgg], asks: Seq[LevelAgg], assetPairDecimals: Option[(Int, Int)] = None) object HttpOrderBook { private val coreTypeSerializers = new SimpleModule() coreTypeSerializers.addDeserializer(classOf[AssetPair], new AssetPairDeserializer) private val mapper = new ObjectMapper() with ScalaObjectMapper mapper.registerModule(DefaultScalaModule) mapper.registerModule(coreTypeSerializers) private def serialize(value: Any): String = mapper.writeValueAsString(value) private class AssetPairDeserializer extends StdDeserializer[AssetPair](classOf[AssetPair]) { override def deserialize(p: JsonParser, ctxt: DeserializationContext): AssetPair = { val node = p.getCodec.readTree[JsonNode](p) def readAssetId(fieldName: String): Asset = { val x = node.get(fieldName).asText(Asset.WavesName) if (x == Asset.WavesName) Waves else IssuedAsset(ByteStr.decodeBase58(x).get) } AssetPair(readAssetId("amountAsset"), readAssetId("priceAsset")) } } private def formatValue(value: BigDecimal, decimals: Int): String = new java.text.DecimalFormat(s"0.${"0" * decimals}").format(value) private def denormalizeAndSerializeSide(side: Seq[LevelAgg], amountAssetDecimals: Int, priceAssetDecimals: Int, jg: JsonGenerator): Unit = { side.foreach { levelAgg => val denormalizedPrice = Denormalization.denormalizePrice(levelAgg.price, amountAssetDecimals, priceAssetDecimals) val denormalizedAmount = Denormalization.denormalizeAmountAndFee(levelAgg.amount, amountAssetDecimals) jg.writeStartArray(2) jg.writeString(formatValue(denormalizedPrice, priceAssetDecimals)) jg.writeString(formatValue(denormalizedAmount, amountAssetDecimals)) jg.writeEndArray() } } def toJson(x: HttpOrderBook): String = serialize(x) class Serializer extends StdSerializer[HttpOrderBook](classOf[HttpOrderBook]) { override def serialize(x: HttpOrderBook, j: JsonGenerator, serializerProvider: SerializerProvider): Unit = { j.writeStartObject() j.writeNumberField("timestamp", x.timestamp) x.assetPairDecimals.fold { j.writeFieldName("pair") j.writeStartObject() j.writeStringField("amountAsset", x.pair.amountAssetStr) j.writeStringField("priceAsset", x.pair.priceAssetStr) j.writeEndObject() j.writeArrayFieldStart("bids") x.bids.foreach(j.writeObject) j.writeEndArray() j.writeArrayFieldStart("asks") x.asks.foreach(j.writeObject) j.writeEndArray() } { case (amountAssetDecimals, priceAssetDecimals) => j.writeArrayFieldStart("bids") denormalizeAndSerializeSide(x.bids, amountAssetDecimals, priceAssetDecimals, j) j.writeEndArray() j.writeArrayFieldStart("asks") denormalizeAndSerializeSide(x.asks, amountAssetDecimals, priceAssetDecimals, j) j.writeEndArray() } j.writeEndObject() } } }