com.fasterxml.jackson.databind.node.ObjectNode Scala Examples
The following examples show how to use com.fasterxml.jackson.databind.node.ObjectNode.
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: JsonRow.scala From eel-sdk with Apache License 2.0 | 5 votes |
package io.eels.util import com.fasterxml.jackson.databind.node.ObjectNode import io.eels.Row object JsonRow { def apply(row: Row): ObjectNode = { val node = JacksonSupport.mapper.createObjectNode() row.map.foreach { case (name, str: String) => node.put(name, str) case (name, long: Long) => node.put(name, long) case (name, int: Integer) => node.put(name, int) case (name, bool: Boolean) => node.put(name, bool) case (name, double: Double) => node.put(name, double) case (name, float: Float) => node.put(name, float) case (name, str) => node.put(name, str.toString) } node } }
Example 2
Source File: AvroSchemaGeneratorSpec.scala From hydra with Apache License 2.0 | 5 votes |
package hydra.avro.util import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.node.ObjectNode import org.scalatest.matchers.should.Matchers import org.scalatest.funspec.AnyFunSpecLike import scala.io.Source class AvroSchemaGeneratorSpec extends Matchers with AnyFunSpecLike { val mapper = new ObjectMapper val converter = new AvroSchemaGenerator() val json = Source .fromFile( Thread.currentThread.getContextClassLoader .getResource("avro-test.json") .getFile ) .getLines() .mkString describe("The json to avro schema converter") { it("Should include a valid namespace and a valid name") { val jsonNode = mapper.readTree(converter.convert(json, "hydra", "name")) jsonNode.at("/namespace").asText shouldBe "hydra" jsonNode.at("/name").asText shouldBe "name" jsonNode.at("/type").asText shouldBe "record" } it("Should have a valid record type") { val jsonNode = mapper.readTree(converter.convert(json, "hydra", "name")) val arrayNode = jsonNode.at("/fields") arrayNode.get(0).at("/type/type").asText shouldBe "record" } it("Should throw an exception with null values") { val jsonNode = mapper.readTree(json) jsonNode.asInstanceOf[ObjectNode].set("dummyString", null) intercept[IllegalArgumentException] { converter.convert(jsonNode.toString(), "hydra", "name") } } it("Should convert booleans") { val clipViewJson = """ |{ | "clipId": "shawn-wildermuth|front-end-web-app-html5-javascript-css-m01|front-end-web-app-html5-javascript-css-m1-02", | "clipModuleIndex": 1, | "clipName": "front-end-web-app-html5-javascript-css-m1-02", | "contentIndexPosition": 99999, | "countsTowardTrialLimits": false, | "courseName": "front-end-web-app-html5-javascript-css", | "courseTitle": "Front-End Web Development Quick Start With HTML5, CSS, and JavaScript", | "ipAddress": "127.0.0.1", | "moduleAuthorHandle": "shawn-wildermuth", | "moduleId": "shawn-wildermuth|front-end-web-app-html5-javascript-css-m01", | "moduleName": "front-end-web-app-html5-javascript-css-m01", | "online": true, | "royaltiesPaid": true, | "started": "2016-11-30T20:30:45.3136582Z", | "userHandle": "44bbf444-ba44-444a-b444-b444bebb4b4b" |} """.stripMargin val jsonNode = mapper.readTree(clipViewJson) val schema = converter.convert(jsonNode.toString(), "hydra", "name") println(schema) } } }
Example 3
Source File: JacksonCompat.scala From circe-jackson with Apache License 2.0 | 5 votes |
package io.circe.jackson import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.databind.{ DeserializationContext, JsonNode, ObjectMapper, ObjectWriter } import com.fasterxml.jackson.databind.node.ObjectNode private[jackson] trait JacksonCompat { protected def makeWriter(mapper: ObjectMapper): ObjectWriter = mapper.writerWithDefaultPrettyPrinter[ObjectWriter]() protected def handleUnexpectedToken(context: DeserializationContext)( klass: Class[_], parser: JsonParser ): Unit = throw context.mappingException(klass) protected def objectNodeSetAll(node: ObjectNode, fields: java.util.Map[String, JsonNode]): JsonNode = node.setAll(fields) }
Example 4
Source File: JacksonCompat.scala From circe-jackson with Apache License 2.0 | 5 votes |
package io.circe.jackson import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.databind.{ DeserializationContext, JsonNode, ObjectMapper, ObjectWriter } import com.fasterxml.jackson.databind.node.ObjectNode private[jackson] trait JacksonCompat { protected def makeWriter(mapper: ObjectMapper): ObjectWriter = mapper.writerWithDefaultPrettyPrinter() protected def handleUnexpectedToken(context: DeserializationContext)( klass: Class[_], parser: JsonParser ): Unit = context.handleUnexpectedToken(klass, parser) protected def objectNodeSetAll(node: ObjectNode, fields: java.util.Map[String, JsonNode]): JsonNode = node.setAll(fields) }
Example 5
Source File: JacksonCompat.scala From circe-jackson with Apache License 2.0 | 5 votes |
package io.circe.jackson import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.databind.{ DeserializationContext, JsonNode, ObjectMapper, ObjectWriter } import com.fasterxml.jackson.databind.node.ObjectNode private[jackson] trait JacksonCompat { protected def makeWriter(mapper: ObjectMapper): ObjectWriter = mapper.writerWithDefaultPrettyPrinter() protected def handleUnexpectedToken(context: DeserializationContext)( klass: Class[_], parser: JsonParser ): Unit = throw context.mappingException(klass) protected def objectNodeSetAll(node: ObjectNode, fields: java.util.Map[String, JsonNode]): JsonNode = node.setAll(fields) }
Example 6
Source File: JacksonCompat.scala From circe-jackson with Apache License 2.0 | 5 votes |
package io.circe.jackson import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.databind.{ DeserializationContext, JsonNode, ObjectMapper, ObjectWriter } import com.fasterxml.jackson.databind.node.ObjectNode private[jackson] trait JacksonCompat { protected def makeWriter(mapper: ObjectMapper): ObjectWriter = mapper.writerWithDefaultPrettyPrinter() protected def handleUnexpectedToken(context: DeserializationContext)( klass: Class[_], parser: JsonParser ): Unit = context.handleUnexpectedToken(klass, parser) protected def objectNodeSetAll(node: ObjectNode, fields: java.util.Map[String, JsonNode]): JsonNode = node.setAll[JsonNode](fields) }