You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.ObjectWriter
import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import org.junit.Test
class JsonSchemaTest {
@Test
def test(): Unit = {
val mapper = new ObjectMapper
mapper.registerModule(DefaultScalaModule)
val generator = new JsonSchemaGenerator(mapper)
val schema = generator.generateSchema(classOf[TestClass])
val writer: ObjectWriter = mapper.writerWithDefaultPrettyPrinter().asInstanceOf[ObjectWriter]
val schemaString = writer.writeValueAsString(schema)
println(schemaString)
}
class TestClass {
var firstName: String = ""
var lastName: String = ""
def firstName(firstName: String) { this.firstName = firstName }
def lastName(lastName: String) { this.lastName = lastName }
}
}
The result sometimes doesn't contain any properties, sometimes only contain firstName. I tried to debug and it is because the getter is not detected correctly because we have 2 methods with the same name
void lastName(String lastName) // generated from def lastName
String lastName() // generated from var lastName
I presume you're running under Java 7+? Non-deterministic behavior of reflection is one of the "features" of Java 7, and I can't repro the use case using Java 6.
Thanks for the report. I should have a fix similar to your suggesting integrated soon.
The result sometimes doesn't contain any properties, sometimes only contain firstName. I tried to debug and it is because the getter is not detected correctly because we have 2 methods with the same name
The code to detect the getter
Unfortunately, findMethod returns the first one, which is refused to be a getter later by filter(isAcceptableGetter)
I fixed this by
Please consider rolling this into master :)
The text was updated successfully, but these errors were encountered: