Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Validate JSON according XSD schema

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Validate JSON according XSD schema

    Hi,

    Some site have REST API that return responses in two formats : xml and JSON .
    Currently I finished basic checks for xml responses of this API .

    Idea was simple - validate xml response using existing xsd schema that clear define what should be inside . I use Jersey (— Project Kenai ) for "speaking" with API and SAX to validate responses.

    Now I need to do the same for JSON format . First big problem here is that I don't have JSON Schema to validate JSON response . So only way that I see is unmarshall JSON response to POJO hierarchy and then validate it against xsd that I have . But this way also raise up hard questions : I can't find Java classes that allow me to do this automatically . Also I can't find classes that allow me to work with xsd in low level - I mean not just general "tell me if this xml is valid according this xsd" but "tell me if this tag can have such children with such types".

    Any ideas , directions or just thoughts are welcome. Maybe somebody can suggest totally different way ? Or somebody can suggest classes that allow to work with xsd on low level ?


  2. #2
    Junior Member
    Join Date
    Feb 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Validate JSON according XSD schema

    Hi All,

    I am currently working on creating a new Json schema which would help a user to sign into an application.

    There are two different ways of logging in:
    1. Username / password
    2. email /password

    Anyone of the above combination given by the user, he should be able to login. I have written two different schemas for this. The schemas goes this way

    1. Username /password schema:
    -------------------------------------

    {
    "required": true,
    "type": "object",
    "additionalProperties": false,
    "properties": {
    "type": {
    "required": true,
    "type": "string",
    },
    "username": {
    "required": true,
    "type": "string",
    },
    "password": {
    "required": true,
    "type": "string",
    }
    }
    }

    2. email /password schema:
    --------------------------------

    {
    "required": true,
    "type": "object",
    "additionalProperties": false,
    "properties": {
    "type": {
    "required": true,
    "type": "string",
    },
    "email": {
    "required": true,
    "type": "string",
    },
    "password": {
    "required": true,
    "type": "string",
    }
    }
    }

    Is there a way to combine these two schemas and match the input given by the user.
    something like: If the type=='email' then switch to email and password combination else switch to username password combination?

    any help would be greatly appreciated.

    Thanks,
    Pradeep

  3. #3
    Junior Member
    Join Date
    Feb 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Validate JSON according XSD schema

    Dear friend can you create separate thread to discuss separate question ?

    This thread was created to get answer on : Validate JSON according XSD schema. Your post is not related to this at all .

Similar Threads

  1. Replies: 3
    Last Post: December 22nd, 2011, 09:46 AM
  2. java validate help??
    By zyspt in forum Java Theory & Questions
    Replies: 1
    Last Post: April 16th, 2010, 02:48 AM
  3. [SOLVED] Web Service Schema input parameter is null
    By wilky in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 8th, 2010, 10:23 AM
  4. Validate in server side..
    By Ganezan in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 27th, 2009, 06:36 AM
  5. Replies: 5
    Last Post: October 12th, 2009, 12:24 AM