On Wed, Oct 21, 2020 at 2:35 PM rajnish <
raj...@gmail.com> wrote:
>
> Thanks Tatu. I will look into the examples that you mentioned and see how we can organize the different version support nicely in parameterized way.
Ok. Also, one thing I would suggest is to consider which schema
versions are widely used, in case some intermediate versions might be
obsolete.
Might make sense to skip some (I assume v5 falls into this category).
> I have two use cases.
> 1) Create Json schema with latest version (preferably, I want to be able to take schema version as parameter in my api)
> 2)Given the Jason schema, convert it into internal proprietary schema. So far, among all the java library I evaluated , no one expose the api to get attributes out of Json schema rather all are focussed solely on doing validation. When I looked in this library, what it appeals to me that I can get a object of type JsonSchema from which I can get all the Json schema attributes. Here is how I am using this.
Interesting. I agree that programmatic access to Schema object is valuable.
Seems odd other packages do not expose that.
>
> val objectMapper = jacksonObjectMapper()
>
> objectMapper.enable(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT)
>
> objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
>
> val jsonSchema: MySchema = objectMapper.readValue(json)
>
> @JsonTypeIdResolver(MyResolver::class)
> class MySchema : ObjectSchema()
>
> internal class MyResolver : JsonSchemaIdResolver() {
> override fun idFromValue(value: Any): String {
> return if (value is MySchema) {
> "object"
> } else super.idFromValue(value)
> }
>
> override fun idFromValueAndType(value: Any, suggestedType: Class<*>?): String {
> return if (value is MySchema) {
> "object"
> } else super.idFromValueAndType(value, suggestedType)
> }
>
> override fun typeFromId(
> ctxt: DatabindContext,
> id: String
> ): JavaType {
> return if ("object" == id) {
> ctxt.constructType(MySchema::class.java)
> } else super.typeFromId(ctxt, id)
> }
> }
-+ Tatu +-
> To view this discussion on the web visit
https://groups.google.com/d/msgid/jackson-dev/fbf29cb7-5416-4b47-a404-ba7069e9daebn%40googlegroups.com.