I have the following JSON data:
{"mapData":{"test":"success","publicKey":""},"statusCode":200,"message":null}
How can I convert this JSON to a TypeScript class?
The mapData contains anonymous values:
- It may be
{"test":"success","publicKey":""}
- Or it may be
{"test":"success","publicKey":"","anotherKey":"anotherValue"}
So, how do we convert this JSON to a TypeScript object?
{"mapData":{"test":"success","publicKey":""},"statusCode":200,"message":null}
Here is an example of my TypeScript demo:
export class GenericResponse {
mapData: any;
statusCode: number;
message: string;
}
Below are the Java classes I used to convert Object to JSON:
/**
* Author: Atwa
* Date: Jul 2, 2018
*/
public class Response {
private Map<String, Object> mapData = new HashMap<>();
private int statusCode = 0;
private String message;
public Map<String, Object> getMapData() {
return mapData;
}
public void setMapData(Map<String, Object> mapData) {
this.mapData = mapData;
}
}