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 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 gson.
Original comment by inder123
on 3 Nov 2010 at 12:25
- Added labels: Milestone-Undefined
from 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 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 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 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 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 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 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 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 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 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 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 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 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 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 gson.
Related Issues (20)
- fromJson(String json, Class<T> classOfT) throws JsonSyntaxException is not thawing exception HOT 1
- 打个广告 gson 10倍速度提升 https://github.com/NBXXF/gson_plugin HOT 1
- About gson multiple field conflict error reporting HOT 1
- Using gson to deserialize error reporting, the gson version I use is 2.10.1 HOT 4
- Why can't Gson serialize the value of the scala.collection.immutable.Map type member variable of the case class into a JSON string,while java.util.HashMap is ok? HOT 1
- Add jackson-databind license header to `ISO8601Utils` and `UtcDateTypeAdapter` HOT 2
- Possible typo at gson readme.md in main branch HOT 2
- Javascript HOT 22
- Gson cannot serialize subclass who override a field HOT 1
- Add support for Optional<T> in parsing instead of null HOT 4
- Poor performance for String serialization HOT 1
- IllegalStateException: TypeToken must be created when using GSON 2.10.1 and R8 on Android HOT 3
- Assertion is Missed to Validate testWriterCloseIsIdempotent Test for JsonWriter's Idempotency
- Assertion is Missed to Validate `testWriterCloseIsIdempotent` Test for JsonWriter's Idempotency HOT 2
- Split `testWriteHtmlSafe` into Two Separate Test Cases for Improved Test Granularity HOT 2
- GSON deserialization fails with ClassCastException: Cannot cast com.google.gson.internal.LinkedTreeMap to androidx.collection.ArrayMap HOT 1
- OSS-Fuzz issue 67620 HOT 3
- Edge case where R8 removes the TypeToken's generic type (while consuming the library's recently updated proguard rules)
- `JsonReader#beginObject` should throw checked exceptions, instead throws runtime `IllegalStateException`. HOT 2
- Serialization failure at index 0 and 1 in camel case field naming convention HOT 2
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 gson.