Loading build.sbt +2 −1 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ lazy val commonSettings = Seq( else Some("releases" at nexus + "service/local/staging/deploy/maven2") }, homepage := Some(url("https://github.com/mbknor/mbknor-jackons-jsonSchema")), homepage := Some(url("https://github.com/mbknor/mbknor-jackson-jsonSchema")), licenses := Seq("MIT" -> url("https://github.com/mbknor/mbknor-jackson-jsonSchema/blob/master/LICENSE.txt")), startYear := Some(2016), pomExtra := ( Loading @@ -40,6 +40,7 @@ val slf4jVersion = "1.7.7" lazy val deps = Seq( "com.fasterxml.jackson.core" % "jackson-databind" % jacksonVersion, "javax.validation" % "validation-api" % "1.1.0.Final", "org.slf4j" % "slf4j-api" % slf4jVersion, "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test", "ch.qos.logback" % "logback-classic" % "1.1.3" % "test", Loading src/main/scala/com/kjetland/jackson/jsonSchema/JsonSchemaGenerator.scala +16 −6 Original line number Diff line number Diff line package com.kjetland.jackson.jsonSchema import java.util import javax.validation.constraints.NotNull import com.fasterxml.jackson.annotation.{JsonSubTypes, JsonTypeInfo} import com.fasterxml.jackson.core.JsonParser.NumberType Loading Loading @@ -294,9 +295,9 @@ class JsonSchemaGenerator(rootObjectMapper: ObjectMapper) { thisObjectNode.set("properties", propertiesNode) Some(new JsonObjectFormatVisitor with MySerializerProvider { override def optionalProperty(writer: BeanProperty): Unit = { val propertyName = writer.getName val propertyType = writer.getType override def optionalProperty(prop: BeanProperty): Unit = { val propertyName = prop.getName val propertyType = prop.getType l(s"JsonObjectFormatVisitor - ${propertyName}: ${propertyType}") val thisPropertyNode = JsonNodeFactory.instance.objectNode() Loading @@ -306,9 +307,18 @@ class JsonSchemaGenerator(rootObjectMapper: ObjectMapper) { objectMapper.acceptJsonFormatVisitor(propertyType, createChild(thisPropertyNode)) // For some types we must set requeired val rawClass = writer.getType.getRawClass if ( rawClass.isPrimitive && rawClass.isAssignableFrom(classOf[Boolean])) { // Check if we should set this property as required val rawClass = prop.getType.getRawClass val requiredProperty:Boolean = if ( rawClass.isPrimitive && rawClass.isAssignableFrom(classOf[Boolean])) { // primitive boolean MUST have a value true } else if(prop.getAnnotation(classOf[NotNull]) != null) { true } else { false } if ( requiredProperty) { getRequiredArrayNode(thisObjectNode).add(propertyName) } Loading src/test/scala/com/kjetland/jackson/jsonSchema/JsonSchemaGeneratorTest.scala +1 −1 Original line number Diff line number Diff line Loading @@ -138,7 +138,7 @@ trait TestData { p } val manyPrimitives = new ManyPrimitives("s1", 1, 2, true, false, 0.1, 0.2, MyEnum.B) val manyPrimitives = new ManyPrimitives("s1", 1, 2, true, false, true, 0.1, 0.2, MyEnum.B) val pojoWithCustomSerializer = { val p = new PojoWithCustomSerializer Loading src/test/scala/com/kjetland/jackson/jsonSchema/testData/ManyPrimitives.java +9 −1 Original line number Diff line number Diff line package com.kjetland.jackson.jsonSchema.testData; import javax.validation.constraints.NotNull; public class ManyPrimitives { public String _string; public Integer _integer; public int _int; public Boolean _boolean; public boolean _boolean2; @NotNull public Boolean _boolean3; public Double _double; public double _double2; public MyEnum myEnum; Loading @@ -13,12 +18,13 @@ public class ManyPrimitives { public ManyPrimitives() { } public ManyPrimitives(String _string, Integer _integer, int _int, Boolean _boolean, boolean _boolean2, Double _double, double _double2, MyEnum myEnum) { public ManyPrimitives(String _string, Integer _integer, int _int, Boolean _boolean, boolean _boolean2, Boolean _boolean3, Double _double, double _double2, MyEnum myEnum) { this._string = _string; this._integer = _integer; this._int = _int; this._boolean = _boolean; this._boolean2 = _boolean2; this._boolean3 = _boolean3; this._double = _double; this._double2 = _double2; this.myEnum = myEnum; Loading @@ -37,6 +43,7 @@ public class ManyPrimitives { if (_string != null ? !_string.equals(that._string) : that._string != null) return false; if (_integer != null ? !_integer.equals(that._integer) : that._integer != null) return false; if (_boolean != null ? !_boolean.equals(that._boolean) : that._boolean != null) return false; if (_boolean3 != null ? !_boolean3.equals(that._boolean3) : that._boolean3 != null) return false; if (_double != null ? !_double.equals(that._double) : that._double != null) return false; return myEnum == that.myEnum; Loading @@ -51,6 +58,7 @@ public class ManyPrimitives { result = 31 * result + _int; result = 31 * result + (_boolean != null ? _boolean.hashCode() : 0); result = 31 * result + (_boolean2 ? 1 : 0); result = 31 * result + (_boolean3 != null ? _boolean3.hashCode() : 0); result = 31 * result + (_double != null ? _double.hashCode() : 0); temp = Double.doubleToLongBits(_double2); result = 31 * result + (int) (temp ^ (temp >>> 32)); Loading Loading
build.sbt +2 −1 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ lazy val commonSettings = Seq( else Some("releases" at nexus + "service/local/staging/deploy/maven2") }, homepage := Some(url("https://github.com/mbknor/mbknor-jackons-jsonSchema")), homepage := Some(url("https://github.com/mbknor/mbknor-jackson-jsonSchema")), licenses := Seq("MIT" -> url("https://github.com/mbknor/mbknor-jackson-jsonSchema/blob/master/LICENSE.txt")), startYear := Some(2016), pomExtra := ( Loading @@ -40,6 +40,7 @@ val slf4jVersion = "1.7.7" lazy val deps = Seq( "com.fasterxml.jackson.core" % "jackson-databind" % jacksonVersion, "javax.validation" % "validation-api" % "1.1.0.Final", "org.slf4j" % "slf4j-api" % slf4jVersion, "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test", "ch.qos.logback" % "logback-classic" % "1.1.3" % "test", Loading
src/main/scala/com/kjetland/jackson/jsonSchema/JsonSchemaGenerator.scala +16 −6 Original line number Diff line number Diff line package com.kjetland.jackson.jsonSchema import java.util import javax.validation.constraints.NotNull import com.fasterxml.jackson.annotation.{JsonSubTypes, JsonTypeInfo} import com.fasterxml.jackson.core.JsonParser.NumberType Loading Loading @@ -294,9 +295,9 @@ class JsonSchemaGenerator(rootObjectMapper: ObjectMapper) { thisObjectNode.set("properties", propertiesNode) Some(new JsonObjectFormatVisitor with MySerializerProvider { override def optionalProperty(writer: BeanProperty): Unit = { val propertyName = writer.getName val propertyType = writer.getType override def optionalProperty(prop: BeanProperty): Unit = { val propertyName = prop.getName val propertyType = prop.getType l(s"JsonObjectFormatVisitor - ${propertyName}: ${propertyType}") val thisPropertyNode = JsonNodeFactory.instance.objectNode() Loading @@ -306,9 +307,18 @@ class JsonSchemaGenerator(rootObjectMapper: ObjectMapper) { objectMapper.acceptJsonFormatVisitor(propertyType, createChild(thisPropertyNode)) // For some types we must set requeired val rawClass = writer.getType.getRawClass if ( rawClass.isPrimitive && rawClass.isAssignableFrom(classOf[Boolean])) { // Check if we should set this property as required val rawClass = prop.getType.getRawClass val requiredProperty:Boolean = if ( rawClass.isPrimitive && rawClass.isAssignableFrom(classOf[Boolean])) { // primitive boolean MUST have a value true } else if(prop.getAnnotation(classOf[NotNull]) != null) { true } else { false } if ( requiredProperty) { getRequiredArrayNode(thisObjectNode).add(propertyName) } Loading
src/test/scala/com/kjetland/jackson/jsonSchema/JsonSchemaGeneratorTest.scala +1 −1 Original line number Diff line number Diff line Loading @@ -138,7 +138,7 @@ trait TestData { p } val manyPrimitives = new ManyPrimitives("s1", 1, 2, true, false, 0.1, 0.2, MyEnum.B) val manyPrimitives = new ManyPrimitives("s1", 1, 2, true, false, true, 0.1, 0.2, MyEnum.B) val pojoWithCustomSerializer = { val p = new PojoWithCustomSerializer Loading
src/test/scala/com/kjetland/jackson/jsonSchema/testData/ManyPrimitives.java +9 −1 Original line number Diff line number Diff line package com.kjetland.jackson.jsonSchema.testData; import javax.validation.constraints.NotNull; public class ManyPrimitives { public String _string; public Integer _integer; public int _int; public Boolean _boolean; public boolean _boolean2; @NotNull public Boolean _boolean3; public Double _double; public double _double2; public MyEnum myEnum; Loading @@ -13,12 +18,13 @@ public class ManyPrimitives { public ManyPrimitives() { } public ManyPrimitives(String _string, Integer _integer, int _int, Boolean _boolean, boolean _boolean2, Double _double, double _double2, MyEnum myEnum) { public ManyPrimitives(String _string, Integer _integer, int _int, Boolean _boolean, boolean _boolean2, Boolean _boolean3, Double _double, double _double2, MyEnum myEnum) { this._string = _string; this._integer = _integer; this._int = _int; this._boolean = _boolean; this._boolean2 = _boolean2; this._boolean3 = _boolean3; this._double = _double; this._double2 = _double2; this.myEnum = myEnum; Loading @@ -37,6 +43,7 @@ public class ManyPrimitives { if (_string != null ? !_string.equals(that._string) : that._string != null) return false; if (_integer != null ? !_integer.equals(that._integer) : that._integer != null) return false; if (_boolean != null ? !_boolean.equals(that._boolean) : that._boolean != null) return false; if (_boolean3 != null ? !_boolean3.equals(that._boolean3) : that._boolean3 != null) return false; if (_double != null ? !_double.equals(that._double) : that._double != null) return false; return myEnum == that.myEnum; Loading @@ -51,6 +58,7 @@ public class ManyPrimitives { result = 31 * result + _int; result = 31 * result + (_boolean != null ? _boolean.hashCode() : 0); result = 31 * result + (_boolean2 ? 1 : 0); result = 31 * result + (_boolean3 != null ? _boolean3.hashCode() : 0); result = 31 * result + (_double != null ? _double.hashCode() : 0); temp = Double.doubleToLongBits(_double2); result = 31 * result + (int) (temp ^ (temp >>> 32)); Loading