Support
Quality
Security
License
Reuse
kandi has reviewed genson and discovered the below as its top functions. This is intended to give you an instant insight into genson implemented functionality, and help decide if they suit your requirements.
Get all kandi verified functions for this library.
Get all kandi verified functions for this library.
Easy to use, fast, highly configurable, lightweight and all that into a single small jar!
Full databinding and streaming support for efficient read/write
Support for polymorphic types (able to deserialize to an unknown type)
Does not require a default no arg constructor and really passes the values not just null, encouraging immutability. It can even be used with factory methods instead of constructors!
Full support for generic types
Easy to filter/include properties without requiring the use of annotations or mixins
Genson provides a complete implementation of JSR 353
Starting with Genson 0.95 JAXB annotations and types are supported!
Automatic support for JSON in JAX-RS implementations
Serialization and Deserialization of maps with complex keys
QUESTION
Representing boolean with enum options in json to generate json schema with genson
Asked 2022-Mar-03 at 18:40I am trying to use genson python library to build a json schema which then will be used on frontend to generate a dynamic form. In this case I want frontend to create a radio button based on schema values. But I have issue with boolean types. For example, this is how my json data looks like
configuration = {
"displayType": {"Opaque":True, "Border":False}
} #Out of the two options here, only one of them can be true.
and this is how i create schema from it.
builder = SchemaBuilder(schema_uri="https://json-schema.org/draft/2020-12/schema")
builder.add_object(configuration)
schema = builder.to_schema()
The generated schema looks like below,
{
'type': 'object',
'properties': {
'Opaque': {
'type': 'boolean'
},
'Border': {
'type': 'boolean'
}
},
'required': ['Border', 'Opaque']
}
As seen above in the required field I need to have info regarding the mutual relationship within one another but I just have a required field. Can anyone help me to modify the json data accordingly?
ANSWER
Answered 2022-Mar-02 at 20:22You can add this to your schema:
'not': {
'properties': {
'Opaque': { 'const': true },
'Border': { 'const': true }
}
}
In pseudocode, that is: "if Opaque is true and Border is true, then validation is false."
Alternatively, because you require both Opaque and Border to be set, and they can only be true or false, you could use if/then/else, as in: "if Opaque is true, then Border is false, else Border is true":
'if': {
'properties': {
'Opaque': { const: true }
}
},
'then': {
'properties': {
'Border': { const: false }
}
},
'else': {
'properties': {
'Border': { const: true }
}
}
You can read more about adding conditions to your schema here: https://json-schema.org/understanding-json-schema/reference/conditionals.html
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
See Similar Libraries in
Save this library and start creating your kit
Open Weaver – Develop Applications Faster with Open Source