Maverik
Maverik

Reputation: 199

RESTful JBoss7 POST JSon gson

I am using JBoss7.1.1. I have to write a RESTful web service that receive a json file. I want to use gson library to deserialize data, is it possible in JBoss7.1.1?

Upvotes: 1

Views: 934

Answers (1)

austin
austin

Reputation: 1171

definitely yes.
But since you are using Restful web service, you could simply use RestEasy annotations(resteasy comes with Jboss 7.1.1)

@Consumes(MediaType.APPLICATION_JSON)

Resteasy would handle the conversion to the object type you mention in the method arguments

TO use Gson
you just have to add Gson library to the classpath to use it in your code

Gson gson=new gson();
Class reference=gson.toJson(yourJsonString,ClassName.class);

if you are using maven: its even more easier, just add Gson dependency in your pom.xml

        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.0</version>
        </dependency>

Upvotes: 1

Related Questions