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

  • SEARCH
  • Home
  • 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 6473109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:25:36+00:00 2026-05-25T06:25:36+00:00

I am writing a deserializer method, which looks like so: public <T> T deserialize(Object[]

  • 0

I am writing a deserializer method, which looks like so:

public <T> T deserialize(Object[] result, String[] fields, Class<T> type);

So basically I will be passed in a result array of data which is all objects, and a class type T which I need to convert the data in the array to the types in the given class, and create a new class of type T and return it. The String[] fields is the field names corresponding to the data in Object[] result. The field names will correspond to the Class T.

The casting will need to use reflection of the given class to find out the type of each field.

eg.

result = ["Mike", "London", 28];
fields = ["name", "location", "age" ];

Class T =

public class GivenClass{

  private String name;
  private String location;
  private Integer age;

  public GivenClass(String name, String location, Integer age){
    this.name = name;
    this.location = location;
    this.age = age;
  }
}
  • 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-25T06:25:37+00:00Added an answer on May 25, 2026 at 6:25 am

    Class implementation

    static class GivenClass {
    
        private String name;
        private String location;
        private Integer age;
    
        public GivenClass(String name, String location, Integer age) {
            this.name = name;
            this.location = location;
            this.age = age;
        }
    
        public GivenClass(Map<String, Object> data) throws Exception {
            for (Field f : GivenClass.class.getDeclaredFields())
                f.set(this, data.get(f.getName()));
        }
    
        public Map<String, Object> serialize() throws Exception {
            Map<String, Object> fields = new HashMap<String, Object>();
            for (Field f : GivenClass.class.getDeclaredFields()) 
                fields.put(f.getName(), f.get(this));
            return fields;
        }
    
        @Override
        public String toString() {
            return "age=" + age + ", location=" + location + ", name=" + name;
        }
    }
    

    Example:

    public static void main(String[] args) throws Exception {
    
        GivenClass o1 = new GivenClass("Mike", "London", 28);
    
        Map<String, Object> serialized = o1.serialize();
    
        GivenClass o2 = new GivenClass(serialized);
        System.out.println(o2.toString());
    }
    

    Output:

    age=28, location=London, name=Mike
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a deserializer like this: public class MyObjectConverter : JavaScriptConverter { public override
I am writing an extension method for parsing JSON string for any given type.
I am writing a class library which abstracts data contained in XML files on
I have a model like this: public PurchaseOrder { [Required] [StringLength(15)] public virtual string
I'm writing a wrapper for a REST API (which is a static class with
i am writing a c# project and i am trying to deserialize an object
Below is the part of a class, I am currently writing, which should take
Writing something like this using the loki library , typedef Functor<void> BitButtonPushHandler; throws a
I am writing a client windows app which will allow files and respective metadata
Currently I'm using XmlSerializer to serialize and deserialize an object. The xml is generated

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.