This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 233131 - Maven Web Service jdbc4 - sql server 2008- glassfish 3.1.2.2 - JSON incomplete, XML is fine
Summary: Maven Web Service jdbc4 - sql server 2008- glassfish 3.1.2.2 - JSON incomplet...
Status: RESOLVED WORKSFORME
Alias: None
Product: webservices
Classification: Unclassified
Component: REST (show other bugs)
Version: 7.3.1
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Milan Kuchtiak
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-22 05:34 UTC by KierenD
Modified: 2013-07-25 08:25 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
User's project (5.68 MB, application/x-7z-compressed)
2013-07-24 07:30 UTC, Milan Kuchtiak
Details

Note You need to log in before you can comment on or make changes to this bug.
Description KierenD 2013-07-22 05:34:48 UTC
Hello.

I have a Maven Web Service jdbc4 - sql server 2008. Testing the service with Fiddler, the JSON seems to be doing some nesting..., and the JSON is not complete. Yet when I request XML, for the same URL, it is fine.


HTTP/1.1 200 OK
X-Powered-By: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.2.2 Java/Oracle Corporation/1.7)
Server: GlassFish Server Open Source Edition 3.1.2.2
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type, Authorization, Accept
Access-Control-Allow-Methods: GET, POST, OPTIONS
Content-Type: application/json
Date: Mon, 22 Jul 2013 05:19:19 GMT

[{"id":1,"metricSize":"<15 kW","imperialSize":"<20 hp","jdcplmodelCollection":[{"id":159,"name":"4110","startDate":1305813600000,"endDate":null,"sizeID":{"id":1,"metricSize":"<15 kW","imperialSize":"<20 hp","jdcplmodelCollection":[{"id":159,"name":"4110","startDate":1305813600000,"endDate":null,"sizeID":{"id":1,"metricSize":"<15 kW","imperialSize":"<20 hp","jdcplmodelCollection":[{"id":159,"name":"4110","startDate":1305813600000,"endDate":null,"sizeID":{"id":1,"metricSize":"<15 kW","imperialSize":"<20 hp","jdcplmodelCollection":[{"id":159,"name":"4110","startDate":1305813600000,"endDate":null,"sizeID":{"id":1,"metricSize":"<15 kW","imperialSize":"<20 
...

Response Body - 67,907 bytes


HTTP/1.1 200 OK
X-Powered-By: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.2.2 Java/Oracle Corporation/1.7)
Server: GlassFish Server Open Source Edition 3.1.2.2
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type, Authorization, Accept
Access-Control-Allow-Methods: GET, POST, OPTIONS
Content-Type: application/xml
Content-Length: 811
Date: Mon, 22 Jul 2013 05:27:37 GMT

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><jDCPLSizes><jdcplSize><id>1</id><imperialSize>&lt;20 hp</imperialSize><metricSize>&lt;15 kW</metricSize></jdcplSize><jdcplSize><id>2</id><imperialSize>20-40 hp</imperialSize><metricSize>15-30 kW</metricSize></jdcplSize><jdcplSize><id>3</id><imperialSize>40-60 hp</imperialSize><metricSize>30-45 kW</metricSize></jdcplSize><jdcplSize><id>4</id><imperialSize>60-80 hp</imperialSize><metricSize>45-60 kW</metricSize></jdcplSize><jdcplSize><id>5</id><imperialSize>80-120 hp</imperialSize><metricSize>60-90 kW</metricSize></jdcplSize><jdcplSize><id>6</id><imperialSize>120-160 hp</imperialSize><metricSize>90-120 kW</metricSize></jdcplSize><jdcplSize><id>7</id><imperialSize>&gt;160 hp</imperialSize><metricSize>&gt;120 kW</metricSize></jdcplSize></jDCPLSizes>



Product Version = NetBeans IDE 7.3.1 (Build 201306052037)
Operating System = Windows 7 version 6.1 running on x86
Java; VM; Vendor = 1.7.0_25
Runtime = Java HotSpot(TM) Client VM 23.25-b01
Java EE 7 Web.


Any advice would be appreciated
Kind regards, Kieren
Comment 1 Milan Kuchtiak 2013-07-23 07:13:57 UTC
The problem seems to be on service provider site. 

How was the (REST) service created? Was that within a Netbeans project?
Could you please attach your Netbeans project to allow us to reproduce the issue.
Comment 2 Milan Kuchtiak 2013-07-24 07:30:30 UTC
Created attachment 137665 [details]
User's project
Comment 3 Milan Kuchtiak 2013-07-24 07:31:17 UTC
User's project attached.
Comment 4 Milan Kuchtiak 2013-07-24 15:10:36 UTC
Managed to reproduce.

It's the default JSON Jackson Provider behavior.

Either customize the default Jackson databinding (Java to JSON), by using Jackson annotations (I am not the expert), or use different JSON provider. The default one in Jersey 2.0 is MOXy, that works perfectly.

I've just commented out the code in ApplicationConfig class, and it works:

    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> resources = new java.util.HashSet<Class<?>>();
//        try {
//            Class jacksonProvider = Class.forName("org.codehaus.jackson.jaxrs.JacksonJsonProvider");
//            resources.add(jacksonProvider);
//        } catch (ClassNotFoundException ex) {
//            System.out.println("ex = "+ex);
//        }
        addRestResourceClasses(resources);
        return resources;
    }
Comment 5 Milan Kuchtiak 2013-07-25 08:25:18 UTC
To avoid the circular references with Jackson JSON provider, you can use the @JsonIgnore annotation for @OneToMany properties, e.g. in

JDCPLSize class, use:

    @XmlTransient
    @JsonIgnore
    public Collection<JDCPLModel> getJDCPLModelCollection() {
        return jDCPLModelCollection;
    }


Used the following dependency:
======================================================
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-core-asl</artifactId>
            <version>1.9.11</version>
            <scope>provided</scope>
        </dependency>
======================================================
Regards