Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6769671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:13:16+00:00 2026-05-26T15:13:16+00:00

In my java app (specifically, Android app), I make a REST call (GET). The

  • 0

In my java app (specifically, Android app), I make a REST call (GET). The response could be either XML or JSON. I use a Strategy Pattern which decides what parser to employ based on the Content Type of the response.

If the response is XML, I use Simple library to parse the response into my POJOs, and if the response is JSON, I use Gson library.

Now my question: Is there any benefit in having a single POJO which containing both Simple and Gson annotations? Or, is it better to separate out the 2 POJOs and then have an Adapter (or maybe Wrapper) to “convert” to a generic POJO? In other words, what are the pros and cons of the following approaches?

Approach 1:

class PojoCommon {

    @SimpleXmlAnnotations
    @GsonAnnotations
    private int age;

    @SimpleXmlAnnotations
    @GsonAnnotations
    private String name;

    //Constructors, Getters and Setters ...
}

Approach 2:

class Pojo{

    private int age;
    private String name;
}

class PojoXml{
    @SimpleXmlAnnotations
    private int age;

    @SimpleXmlAnnotations
    private String name;

    public Pojo toGenericPojo(){
        return new Pojo(this.age, this.name);
    }
}

class PojoJson{

    @GsonAnnotations
    private int age;

    @GsonAnnotations
    private String name;

    public Pojo toGenericPojo(){
        return new Pojo(this.age, this.name);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:13:17+00:00Added an answer on May 26, 2026 at 3:13 pm

    Though Approach1 is better in term of maintenance but you already have answered your question as in long term with any proposed changes it can make things complex.

    My Suggestion is to go for second one create POJO for each individual type and use a wrapper/adapter approach for the conversion

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an Android app, specifically one that uses the Facebook Android SDK.
Our Java app writes to MQ Series queues via a Weblogic JMS Message Bridge.
While working in a Java app, I recently needed to assemble a comma-delimited list
In my SWT Java app I often want to return information from inside a
I have a standalone Java app that has some licensing code that I want
I have a large Java app that is split up into multiple projects. Each
I'm writing a java app using eclipse which references a few external jars and
I'm developing a Java app on the Windows platform, and my application needs to
In a java app, assuming I have option of choosing the following comparison methods
In my Java app I am trying to create a very simple form with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.