Comments (17)
FYI... I've started implementing a JsonValidator class to do just this based on
top
of the Gson library. I have only implemented the validation I have needed so
far,
but I can post it if you are interested.
Original comment by [email protected]
on 14 Apr 2009 at 8:33
from google-gson.
It would be great if you can either post it in a forum, or create a new
open-source
project that we can point people to for this.
Thanks
Original comment by inder123
on 14 Apr 2009 at 8:41
from google-gson.
Original comment by inder123
on 3 Nov 2010 at 12:25
- Added labels: Milestone-Undefined
from google-gson.
Original comment by limpbizkit
on 24 Jan 2011 at 10:21
- Changed title: Json + schema
- Added labels: Priority-Low
- Removed labels: Priority-Medium
from google-gson.
Joel pointed me to this IETF draft
http://tools.ietf.org/html/draft-zyp-json-schema-03
I don't like it because it is not simple. It has many features that should be
left up to the application-level: value range checking, hrefs, IDs, enums,
inheritance, refs, etc. These all remind me of XML, which is why we all like
JSON so much.
Original comment by limpbizkit
on 15 Feb 2011 at 12:21
from google-gson.
@limpbizkit: I generally agree with your concerns about using a schema language.
However, the big advantage of a schema language is that it is language neutral
documentation. Currently, the Java Objects used by Gson is the real
specification. Having a schema would be nice.
Original comment by inder123
on 8 Jul 2011 at 3:31
from google-gson.
@inder123: ya, a specification can provide a neutral guide to do interaction
with other language or platform. But implementing such a specification is a
time-consuming work. For your experience, how much work it should take to do
this work? you know, I am really interested in it.
Original comment by alloyer
on 8 Jul 2011 at 3:42
from google-gson.
It is not going to be too much work. How about you experiment with generating
DOM with Gson by using Gson.toJsonTree() method. Currently
Gson.toJson(JsonElement e) method prints the JSON for the DOM tree. Instead,
you need to output the schema. Should be as simple as walking through each of
the DOM nodes and writing schema elements to the output.
Original comment by inder123
on 8 Jul 2011 at 5:11
from google-gson.
There are plenty of time, users choose XML, for it's concrete schema validation
feature. a quick solution on top of my head , may be not so efficient, we can
abstract. That is
convert json schema in to xml one (less work I assume)
use xml validation feature to verify data.
Original comment by [email protected]
on 8 Jul 2011 at 5:37
from google-gson.
I am starting the work to describe a Java type in Json schema. But I can't get
how to describe the generic type of a list? I know I can use "array" to
represent a List type, but where to set the entity type for the List?
Original comment by alloyer
on 11 Jul 2011 at 8:50
from google-gson.
Might be worth asking this question on the JSON Schema group:
https://groups.google.com/forum/#!forum/json-schema
I am actually not sure if this JSON schema is the most popular schema language
for JSON. Please look around to see if you find a schema language that is
complete and has gained most traction.
Original comment by inder123
on 11 Jul 2011 at 8:57
from google-gson.
Here is a pointer to another schema language for JSON:
http://tools.ietf.org/html/draft-zyp-json-schema-03
It seems like this one is from IETF so is more official. Please help figure out
which is the most popular schema language.
Original comment by inder123
on 11 Jul 2011 at 9:00
from google-gson.
If we ever do this, I'd prefer we do it as an optional extension.
Original comment by limpbizkit
on 29 Dec 2011 at 5:50
from google-gson.
It only took me 2 years to get around to posting it, but here is the JSON
Validation code a wrote a while ago.
Feel free to do with it as you will. If (within the next few years) I create a
opensource project for it, I'll post here. If someone else does, please post a
note here so that I can follow it.
Thanks.
Original comment by [email protected]
on 6 Feb 2012 at 10:44
Attachments:
from google-gson.
FYI, you have a bug on line 118. It should be
ANY.getTypeString().equals(type)), not ANY.equals(type) -- in the latter case,
you're using equals() to compare an Enum<Type> and a String.
Original comment by [email protected]
on 7 Feb 2012 at 2:48
from google-gson.
Thanks for pointing that out.
FYI, I use JSON for my web APIs. I use the schema as an easy way of validating
input (and output) data. Since I use the schema file for validation in my
code, I can publish it and provides a definitive documentation of the API. For
this, I find it really useful.
Original comment by [email protected]
on 10 Feb 2012 at 11:50
from google-gson.
I don't think we're gonna get to this.
Original comment by limpbizkit
on 16 Apr 2012 at 10:47
- Changed state: WontFix
from google-gson.
Related Issues (20)
- Should support custom serializers for map keys HOT 4
- please add support for getter method HOT 1
- Permit type data in the serialized JSON HOT 7
- Unbearable when toJson a long string(1M) HOT 2
- Gson should provide a way to configure order for field navigation HOT 5
- Not able to deserialize. HOT 2
- Not able to deserialize. HOT 3
- support java.sql.Date and Timestamp types HOT 6
- Having an inner class gives this error - No-args constructor for B does not exist. HOT 1
- Extend Expose annotation to support classes HOT 3
- Support circular references HOT 18
- Gson should have a way to provide custom exclusion strategies HOT 2
- all should be strings HOT 2
- Error Deserializing objects using fromJson(string, type) HOT 4
- com.google.gson.Gson should be able to toJson JsonElements/JsonObjects HOT 3
- Deserialization/Serialization issue when json is injected via spring annotations HOT 5
- Set formatting style in pretty printing HOT 1
- suggestion: Add @Verification annotation for easy verification of POJO validity HOT 6
- compilation via maven fails due to generics bug in javac HOT 1
- Gson needs a more obust inclusion and exclusion mechanism HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from google-gson.