In our legacy code, we are sending request body in a form of a HashMap, something I cannot change because other applications may be affected.
Sample Hashmap value = {name=name1, age=age1}
However I have problem on using HashMap if there are multiple JSON objects in my request, for example
HashMap<String, Object> map = new HashMap<String, Object>();
for (Person person: Persons) {
map.put("name", "name1");
map.put("age", "age1");
}
If there are 2 or more people, only the last person's name and age will be put in the Map, because the first person's name and age are overridden because they have the same key ("name" and "age").
My desired map value was [{name=name1, age=age1}, {name=name2, age=age2}], but I only got {name=name2, age=age2}
What I did is, in every loop, I put it in JSONArray:
JSONArray jsonArray = new jsonArray();
for (Person person: Persons) {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("name", "name1");
map.put("age", "age1");
jsonArray.put(map);
}
So when I print JSONArray, it is:
[{"name":"name1", "age":"age1"}, {"name":"name2", "age":"age2"}]
But again, I need to transform this into HashMap so I can pass it as parameter to oursendRequest() method.
I tried to use the ObjectMapper in Jackson, but it didn't work.
Is this possible, and how?
I would deserialize the JSON into a List of people first. After that, I would group them by name.
Main.java
package q61078696;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.*;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;
public class Main {
public static void main(String[] args) {
try {
List<Person> people = loadJSON("q61078696/people.json", Person.class);
Map<String, List<Person>> groupedByName = people.stream()
.collect(Collectors.groupingBy(Person::getName));
System.out.println(groupedByName);
} catch (Exception e) {
e.printStackTrace();
}
}
public static String loadJSON(String resourceName) {
InputStream is = Main.class.getClassLoader().getResourceAsStream(resourceName);
String jsonString = null;
try (Scanner scanner = new Scanner(is, StandardCharsets.UTF_8.name())) {
jsonString = scanner.useDelimiter("\\A").next();
}
return jsonString;
}
public static <E> List<E> loadJSON(String resourceName, Class<E> clazz) throws IOException {
ObjectMapper mapper = new ObjectMapper();
String jsonString = loadJSON(resourceName);
CollectionType typeReference = TypeFactory.defaultInstance().constructCollectionType(List.class, clazz);
return mapper.readValue(jsonString, typeReference);
}
}
Output
{Tom=[{ "name": "Tom", "age": 28 }], Bob=[{ "name": "Bob", "age": 42 }, { "name": "Bob", "age": 21 }], Mary=[{ "name": "Mary", "age": 35 }]}
Person.java
package q61078696;
public class Person {
private String name;
private int age;
public Person() {
this(null, 0);
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
#Override
public String toString() {
return String.format("{ \"name\": \"%s\", \"age\": %d }", this.name, this.age);
}
}
people.json
[
{ "name" : "Bob", "age" : 42 },
{ "name" : "Bob", "age" : 21 },
{ "name" : "Mary", "age" : 35 },
{ "name" : "Tom", "age" : 28 }
]
Dependencies
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.8</version>
</dependency>
Additional Info
If you want to map by name and avoid grouping (ignoring dupes).
This will throw an IllegalStateException, because there are duplicate keys, to avoid this, you will need to access the map.
Map<String, Person> groupedByName = people.stream()
.collect(Collectors.toMap(Person::getName, Function.identity()));
You can avoid this by specifying a mergeFunction
Map<String, Person> groupedByName = people.stream()
.collect(Collectors.toMap(
Person::getName, // keyMapper
Function.identity(), // valueMapper
(o1, o2) -> o1, // mergeFunction (keep the first occurrence)
TreeMap::new) // mapSupplier
);
You can also specify a supplier in the 4th parameter. I chose a TreeMap to keep the name keys in order.
See: https://docs.oracle.com/javase/8/docs/api/java/util/stream/Collectors.html#toMap-java.util.function.Function-java.util.function.Function-java.util.function.BinaryOperator-
Related
Say I have a list of of Objects (say List<User>), something like
[
{
"name": "myName",
"age": 1,
"someField": "foo"
},
{
"name": "otherName",
"age": 2,
"someField": "bar"
},
]
I want to convert this to Set<Map<String, Integer>> such that I get a set of name => age pair. So final result should be [{"myName": 1},{"otherName": 2}]
How can I use the stream and collector to do this?
You can use below piece of code for parsing JSON String and then doing some manipulation with that :
public static void main(String[] args) {
String str = "[ { \"name\": \"myName\", \"age\": 1, \"someField\": \"foo\" }, { \"name\": \"otherName\", \"age\": 2, \"someField\": \"bar\" }, ]";
JSONArray jsonobj = new JSONArray(str);
Map<String,Integer> map = new HashMap<>();
for(int i = 0;i<jsonobj.length();i++){
JSONObject obj = jsonobj.getJSONObject(i);
map.put(obj.getString("name"), obj.getInt("age"));
}
Set<Map<String,Integer>> set = new HashSet<>();
set.add(map);
System.out.println(set);
}
Library used : org.json
I ended up doing this:
final List<User> users = new ArrayList<>();
users.add(user1);
users.add(user2);
users.add(user3);
Set<Map<String, Integer>> usersSet =
users
.stream()
.map(u -> Collections.singletonMap(u.getName(), u.getAge()))
.collect(Collectors.toSet());
Here is a possible conversion to Map<String, Integer> with duplicate handling:
final List<User> users = new ArrayList<>();
users.add(new User("name 1", 25));
users.add(new User("name 1", 49));
users.add(new User("name 2", 67));
final Map<String, Integer> nameToAge = users.stream().collect(
Collectors.toMap(
user -> user.name,
user -> user.age,
(user1, user2) -> {
System.out.println("Resolving duplicates...");
return user1;
})
);
In this case the definition for type User is:
public class User {
public final String name;
public final int age;
public User(final String name, final int age) {
this.name = name;
this.age = age;
}
}
I have a JSON-String array, where its entry has the following properties, firstName, lastName, loginName, Country, phoneNumber, and status. Here's an example
[
{
"firstName": "Patrick",
"lastName": "Smith",
"loginName":"test0003#test.com",
"Country":"US",
"phoneNumber": "287 125-1434",
"status": "340"
},
{
"firstName": "Bob",
"lastName": "Williams",
"loginName":"test0002#test.com",
"Country":"US",
"phoneNumber": "213 111-9943",
"status": "215"
},
{
"firstName": "John",
"lastName": "Johnson",
"loginName":"test0001#test.com",
"Country":"DE",
"phoneNumber": "212 555-1234",
"status": "167"
},
{
"firstName": "George",
"lastName": "Jones",
"loginName":"test0004#test.com",
"Country":"FR",
"phoneNumber": "217 987-2634",
"status": "340"
}
]
Now, I want to search for a specific entry based on the properties loginName and status
For example
loginName: test0001#test.com
status: 167
{
"firstName": "John",
"lastName": "Johnson",
"loginName":"test0001#test.com",
"Country":"DE",
"phoneNumber": "212 555-1234",
"status": "167"
}
What would be the most optimized solution?
I use JSONObject and here is another way to parse.
1. Parse using JSONArray
2. Loop the array and read into UserProfile objects
3. Store it in HashMap to get using key
import java.util.HashMap;
import java.util.Map;
import org.json.*;
class UserProfile{
String loginName;
int status;
String firstName;
String key;
UserProfile(){
}
String getLoginName(){
return loginName;
}
String getFirstName(){
return firstName;
}
void setKey(String key){
this.key = key;
}
void setLoginName(String loginName){
this.loginName = loginName;
}
void setStatus(int status){
this.status = status;
}
void setFirstName(String firstName){
this.firstName = firstName;
}
}
public class JSONObjParser {
public static void main(String[] args){
Map<String, UserProfile> map = new HashMap<String, UserProfile>();
String msg ="[{ firstName: Patrick, lastName: Smith, loginName:test0003#test.com, Country:US, phoneNumber: 287 125-1434, status: 340 }, { firstName: Bob, lastName: Williams, loginName:test0002#test.com, Country:US, phoneNumber: 213 111-9943, status: 215 }]";
JSONArray jsonarray = new JSONArray(msg);
for (int i = 0; i < jsonarray.length(); i++) {
JSONObject jsonobject = jsonarray.getJSONObject(i);
String loginName = jsonobject.getString("loginName");
int status = jsonobject.getInt("status");
String firstName = jsonobject.getString("firstName");
UserProfile profile = new UserProfile();
profile.setFirstName(firstName);
profile.setLoginName(loginName);
profile.setStatus(status);
String key = loginName + Integer.toString(status);
map.put(key, profile);
}
for (String key : map.keySet()) {
UserProfile profile = map.get(key);
System.out.println("Key = " + key + ", FirstName = " + profile.getFirstName());
}
}
}
Using Jackson, this is the crudest snippet I can think of:
private static ObjectMapper mapper = new ObjectMapper();
public static void main(String[] args) throws IOException {
System.out.println(filterJsonArray(JSON, "loginName", "test0001#test.com", "status", "167"));
}
public static String filterJsonArray(String array, String keyOne, Object valueOne, String keyTwo, Object valueTwo) throws IOException {
Map[] nodes = mapper.readValue(array, HashMap[].class);
for (Map node : nodes) {
if (node.containsKey(keyOne) && node.containsKey(keyTwo)) {
if (node.get(keyOne).equals(valueOne) && node.get(keyTwo).equals(valueTwo)) {
return mapper.writeValueAsString(node);
}
}
}
return null;
}
Of course it will only returns the first match to the given pairs. If you need all the values, make it return a list instead and populate it inside the loop.
Working on building the model for an application dealing with physical buildings.
Ideally, we'd want something like this:
City has multiple Offices, which have multiple Rooms, which have properties.
We're using jackson to parse the JSON payload received from the API datasource, and it ends up looking a bit differently than the examples I've seen.
The format we're getting is:
{
"CityName1":
{ "OfficeName1":
[
{"name": RoomName1, "RoomProperty2": RoomValue1},
{"name": RoomName2, "RoomProperty2": RoomValue2}
]
},
{ "OfficeName2": [{...}]},
{ "OfficeNameX" : [{...}] },
"CityName2": {...},
"CityNameN": {...}}
Java classes:
public class City {
private Map<String, Object> additionalProperties = new HashMap<String, Object();
private List<Office> _offices = new ArrayList<Office>();
#JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
#JsonAnySetter
public void setAdditionalProperty(String name, Object value)
throws IOException {
_cityName = name;
String officeJson = _mapper.writeValueAsString(value);
StringBuilder sb = new StringBuilder(officeJson);
_offices.add(_mapper.readValue(officeJson, Office.class));
this.additionalProperties.put(name, value);
}
}
public class Office {
private String _officeName;
private static final ObjectMapper _mapper = new ObjectMapper();
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
private List<Room> _rooms = new ArrayList<Room>();
#JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
#JsonAnySetter
public void setAdditionalProperty(String name, Object value)
throws IOException {
_officeName = name;
String roomJson = _mapper.writeValueAsString(value);
Room[] rooms = _mapper.readValue(roomJson, Room[].class);
_rooms.addAll(Arrays.asList(rooms));
this.additionalProperties.put(name, value);
}
public List<Room> getRooms() {
return _rooms;
}
public void setRooms(List<Room> rooms) {
_rooms = rooms;
}
}
public class Room {
private static final String NAME = "name";
private static final String PROP_2 = "RoomProperty2";
#JsonProperty(PROP_2)
private String _propertyTwo;
#JsonProperty(NAME)
private String name;
#JsonProperty(PROP_2)
public String getPropertyTwo() {
return _propertyTwo;
}
#JsonProperty(PROP_2)
public void setPropertyTwo(String propTwo) {
_propertyTwo = propTwo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
So how would I go about parsing this with jackson ? Currently, I am using an #JsonAnySetter to grab the name, and saving that as the city or office name and then sending the value sent to JsonAnySetter to the appropriate nested class. The real issue comes with getting a list of Offices in the City. When using a mapper.readvalues(String, Office.class), I get returned an iterator of only the last office for each city. Any ideas guys?
Sorry if that seemed confusing! Would love to answer any questions I've created.
Thanks for the help!
I think the best solution is to write your own deserialiser here since your JSON document doesn't really map well to the class structure you want.
The solution below reads each city as a Map<String, List<Room>> and the collection of cities as a Map<String, City> and then create City and Office objects from these inside the deserialisers.
Room.java is the same as yours, here are the rest:
Cities.java:
#JsonDeserialize(using=CitiesDeserializer.class)
public class Cities implements Iterable<City> {
private final List<City> cities;
public Cities(final List<City> cities) {
this.cities = cities;
}
public Cities() {
this.cities = new ArrayList<>();
}
public List<City> getCities() {
return cities;
}
#Override
public Iterator<City> iterator() {
return cities.iterator();
}
}
CitiesDeserialiser.java:
public class CitiesDeserializer extends JsonDeserializer<Cities> {
private static final TypeReference<Map<String, City>> TYPE_REFERENCE = new TypeReference<Map<String, City>>() {};
#Override
public Cities deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException {
final Map<String, City> map = jp.readValueAs(TYPE_REFERENCE);
List<City> cities = new ArrayList<>();
for(Map.Entry<String, City> entry : map.entrySet()) {
City city = entry.getValue();
city.setName(entry.getKey());
cities.add(city);
}
return new Cities(cities);
}
}
City.java:
#JsonDeserialize(using=CityDeserialzer.class)
public class City {
private String name;
private List<Office> offices;
// Setters and getters
}
CityDeserializer.java:
public class CityDeserialzer extends JsonDeserializer<City> {
private static final TypeReference<Map<String, List<Room>>> TYPE_REFERENCE = new TypeReference<Map<String, List<Room>>>() {};
#Override
public City deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException {
final Map<String, List<Room>> map = jp.readValueAs(TYPE_REFERENCE);
List<Office> offices = new ArrayList<>();
for(Map.Entry<String, List<Room>> entry : map.entrySet()) {
Office office = new Office();
office.setName(entry.getKey());
office.setRooms(entry.getValue());
offices.add(office);
}
City city = new City();
city.setOffices(offices);
return city;
}
}
Office.java:
public class Office {
private String name;
private List<Room> rooms;
// Setters and getters
}
And here's a test to show that it works:
JSON:
{
"CityName1": {
"OfficeName1": [ {
"name": "RoomName1",
"RoomProperty2": "RoomValue1"
}, {
"name": "RoomName2",
"RoomProperty2": "RoomValue2"
} ],
"OfficeName2": [ {
"name": "RoomName3",
"RoomProperty2": "RoomValue3"
}, {
"name": "RoomName4",
"RoomProperty2": "RoomValue4"
} ]
},
"CityName2": {
"OfficeName3": [ {
"name": "RoomName5",
"RoomProperty2": "RoomValue5"
}, {
"name": "RoomName6",
"RoomProperty2": "RoomValue6"
} ],
"OfficeName4": [ {
"name": "RoomName7",
"RoomProperty2": "RoomValue7"
}, {
"name": "RoomName8",
"RoomProperty2": "RoomValue8"
} ]
}
}
Test.java:
public class Test {
public static void main(String[] args) {
String json = ...
ObjectMapper mapper = new ObjectMapper();
Cities cities = mapper.readValue(json, Cities.class);
for(City city : cities) {
System.out.println(city.getName());
for(Office office : city.getOffices()) {
System.out.println("\t" + office.getName());
for(Room room : office.getRooms()) {
System.out.println("\t\t" + room.getName());
System.out.println("\t\t\t" + room.getPropertyTwo());
}
}
}
}
}
Output:
CityName1
OfficeName1
RoomName1
RoomValue1
RoomName2
RoomValue2
OfficeName2
RoomName3
RoomValue3
RoomName4
RoomValue4
CityName2
OfficeName3
RoomName5
RoomValue5
RoomName6
RoomValue6
OfficeName4
RoomName7
RoomValue7
RoomName8
RoomValue8
My generic method gives casting exception.
java.util.LinkedHashMap cannot be cast to com.example.model.Student
main class
public static void main(String[] args) {
Map<String, Student> students = SampleClass.getStudents("students.json");
System.out.println(students.get("student1").getName());
}
SampleClass
public static <T> Map<String, T> getStudents(String filename) {
Map<String, T> studentMap = null;
ObjectMapper mapper = new ObjectMapper();
try {
studentMap = mapper.readValue(new File(filename),
new TypeReference<Map<String, T>>() { });
} catch (JsonParseException e) {
System.out.println(e.getMessage());
} catch (JsonMappingException e) {
System.out.println(e.getMessage());
} catch (IOException e) {
System.out.println(e.getMessage());
}
return (Map<String, T>)studentMap;
}
what I'm doing wrong?
UPDATE
json file
{
"student1" :
{
"name" : "name1",
"age" : 22
},
"student2" :
{
"name" : "name2",
"age" : 22
}
}
UPDATE
found this as solution.
The problem is with your TypeReference<Map<String, T>>. When you give T here jackson will try to infer the type. Since at this point jackson doesnt know anything about Student class it infer the "name" : "name1" to be a LinkedHashMap with key "name" and value "name1". So in-turn it creates a LinkedHashMap<String, LinkedHashMap<String>>.
As a quick solution you in the object mapper method you could use TypeReference as
studentMap = mapper.readValue(new File(filename), new TypeReference<Map<String, Student>>() { });
Since the method is getStudents it make sense to use this TypeReference but then the whole point of generics in that method is wasted.
Another approach would be to use a custom deserializer. There are many ways of doing this. You could find the details in http://wiki.fasterxml.com/JacksonPolymorphicDeserialization
For example lets make a marker interface for all possible class use a custom deserializer. Say for you scenario lets say we have an interface StudentI which will be implemented by all possible classes you type T could have. Then use the #JsonTypeInfo to give additional details about the class
Student interface
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
#JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
property = "type")
#JsonSubTypes({
#Type(value = Student.class, name = "student") })
public interface StudentI {
}
This means if you give something like 'type : student' in your json the mapper would use Student.class for you T.
Sample Class
import java.io.File;
import java.io.IOException;
import java.util.Map;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
public class SampleClass {
public static <T extends StudentI> Map<String, T> getStudents(String filename) {
Map<String, T> studentMap = null;
ObjectMapper mapper = new ObjectMapper();
try {
studentMap = mapper.readValue(new File(filename),
new TypeReference<Map<String, StudentI>>() { });
} catch (JsonParseException e) {
System.out.println(e.getMessage());
} catch (JsonMappingException e) {
System.out.println(e.getMessage());
} catch (IOException e) {
System.out.println(e.getMessage());
}
return (Map<String, T>)studentMap;
}
}
Students.json
{
"student1" :
{
"name" : "name1",
"age" : 22,
"type" : "student"
},
"student2" :
{
"name" : "name2",
"age" : 22,
"type" : "student"
}
}
Now your Student class should implement this interface
public class Student implements StudentI {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
#Override
public String toString() {
return "Student [name=" + name + ", age=" + age + "]";
}
}
Once this is done your code would work just as expected
public static void main(String[] args) {
Map<String, Student> students = SampleClass.getStudents("students.json");
System.out.println(students.get("student1").getName());
}
//Output : name1
Depends what's in your json file. Looks like the mapper is returning a Student object rather than a map.
I have a JSON string like:
"shipping_profiles": {
"563": {
"name": "name",
"value": "value"
},
"564": {
"name": "name",
"value": "value"
},
"565": {
"name": "name",
"value": "value"
},
"566": {
"name": "name",
"value": "value"
}
}
Now I am parsing it with Jackson 2.0.
I am trying to get a List<shipping_profiles> from the JSON string.
Is it possible?
Your shipping_profiles property doesn't look like array. It represent object with dynamic properties, so we should treat it like an object. If we do not know anything about properties we can use #JsonAnySetter annotation. Algorithm could looks like below:
Deserialize JSON into JSON-model classes.
Convert dynamic objects (maps) into app's POJO classes using ObjectMapper
Use app's POJO whenever you want.
Please see my example implementation. I hope, it help you solve your problem. Input JSON:
{
"shipping_profiles":{
"563":{
"name":"name563",
"value":"value563"
},
"564":{
"name":"name564",
"value":"value564"
},
"565":{
"name":"name565",
"value":"value565"
},
"566":{
"name":"name566",
"value":"value566"
}
}
}
Example program:
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
public class JacksonProgram {
public static void main(String[] args) throws IOException {
ObjectMapper mapper = new ObjectMapper();
File source = new File("X:/test.json");
Entity entity = mapper.readValue(source, Entity.class);
ShippingProfiles shippingProfiles = entity.getShippingProfiles();
List<Map<String, String>> profileMaps = shippingProfiles.getProfiles();
List<Profile> profiles = new ArrayList<Profile>(profileMaps.size());
for (Map<String, String> item : profileMaps) {
profiles.add(mapper.convertValue(item, Profile.class));
}
System.out.println(profiles);
}
}
class Entity {
#JsonProperty("shipping_profiles")
private ShippingProfiles shippingProfiles;
public ShippingProfiles getShippingProfiles() {
return shippingProfiles;
}
public void setShippingProfiles(ShippingProfiles shippingProfiles) {
this.shippingProfiles = shippingProfiles;
}
}
class ShippingProfiles {
private List<Map<String, String>> profiles = new ArrayList<Map<String, String>>();
#JsonAnySetter
public void setDynamicProperty(String name, Map<String, String> map) {
profiles.add(map);
}
public List<Map<String, String>> getProfiles() {
return profiles;
}
public void setProfiles(List<Map<String, String>> profiles) {
this.profiles = profiles;
}
}
class Profile {
private String name;
private String value;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
#Override
public String toString() {
return "Profile [name=" + name + ", value=" + value + "]";
}
}
Above app prints:
[Profile [name=name563, value=value563], Profile [name=name564, value=value564], Profile [name=name565, value=value565], Profile [name=name566, value=value566]]
I got my json with dynamic property parsed with the way #michalziober provide.
"commandClasses": {
"32": {
"name": "Basic",
"data": {
"name": "devices.1.instances.1.commandClasses.32.data",
"value": null,
"type": "NoneType"
},
"38": {
"name": "SwitchMultilevel",
"data": {
"name": "devices.1.instances.1.commandClasses.38.data",
"value": null,
"type": "NoneType"
},
"43": {
"name": "SceneActivation",
"data": {
"name": "devices.1.instances.1.commandClasses.43.data",
"value": null,
"type": "NoneType"
}
With this json I also need to save that dynamic property, so I add another List for storing it.
public class CommandClasses {
private List<String> nameList = new ArrayList<String>();
private List<CommandClass> commmandClasses = new ArrayList<CommandClass>();
private Logger logger = Logger.getInstance(CommandClasses.class);
#JsonAnySetter
public void setDynamicCommandClass(String name, CommandClass cc) {
logger.d("# adding new CC : " + name);
nameList.add(name);
commmandClasses.add(cc);
}
public List<CommandClass> getCommmandClasses() {
return commmandClasses;
}
public void setCommmandClasses(List<CommandClass> commmandClasses) {
this.commmandClasses = commmandClasses;
}
}
Now I can also access the field as id to send out request later.