How to get key set of serialized json object in servlet for post form processing | Community
Skip to main content
srinivas_chann1
New Participant
February 23, 2023
Solved

How to get key set of serialized json object in servlet for post form processing

  • February 23, 2023
  • 2 replies
  • 793 views

Hello,

 

could someone please provide inputs if there a possibility for  getting all the field names as

 keyset so that need not hardcode the formDataObject keys as per below??

 

 

1>

I have a form json data and have created 

public class FormRequestJsonData {

    @SerializedName("field1")

    @expose

    private String field1;

 

@SerializedName("field2")

    @expose

    private String field2;

 

....

@SerializedName("field20")

    @expose

    private String field20;

}

  2>for the JsonObject  content

{
    "field1" : "string",
    "field2" : "string",

....
"field20" : "string" }

 

I have about 20 fields and on serializing like below 

FormRequestJsonData formDataObject = new GsonBuilder().create().fromJson(
                content, FormRequestJsonData.class);

 

I will need to some dynamic processing for each field in formDataObject with xssapi validation.

So need to get each key and need to write  xssapi.filter code.

Is there a possibility for the getting all the field names as keyset so that need not hardcode the formDataObject keys

currently doing

if("field1"){

xssapi.filterhtml(formDataObject.getField1());

}

if("field2"){

xssapi.filterhtml(formDataObject.getField2());

}

Regards,

Srinivas

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

There is a way to do that, 

you can map String response to map. this will give you key and value in map format

 

private List<Map<String, Object>> fragment = new ArrayList<>();

2 replies

arunpatidar
arunpatidarAccepted solution
New Participant
February 24, 2023

There is a way to do that, 

you can map String response to map. this will give you key and value in map format

 

private List<Map<String, Object>> fragment = new ArrayList<>();
Arun Patidar
srinivas_chann1
New Participant
February 23, 2023

Hello,

 

Any inputs from anyone on this

 

Thanks