Hi,
We have an api response that is saved as string in a field in Table1. And let's say we have these contracts to match the saved json string.
[DataContractAttribute]
class IndividualDataContract
{
private str firstName;
private str lastName;
private int age;
private str city;
private List hobbies;
[DataMemberAttribute('first_name')]
public str parmFirstName(str _firstName = firstName)
{
firstName = _firstName;
return firstName;
}
[DataMemberAttribute('last_name')]
public str parmLastName(str _lastName = lastName)
{
lastName = _lastName;
return lastName;
}
[DataMemberAttribute('age')]
public int parmAge(int _age = age)
{
age = _age;
return age;
}
[DataMemberAttribute('city')]
public str parmCity(str _city = city)
{
city = _city;
return city;
}
[DataMemberAttribute('hobbies')AifCollectionTypeAttribute('_hobbies',Types::Class, classStr(HobbyDataContract)),
AifCollectionTypeAttribute('return',Types::Class, classStr(HobbyDataContract))]]
public List parmHobbies(List _hobbies = hobbies)
{
hobbies = _hobbies;
return hobbies;
}
[DataContractAttribute]
class HobbyDataContract
{
private str type;
private str level;
[DataMemberAttribute('type')]
public str parmType(str _type = type)
{
type = _type;
return type;
}
[DataMemberAttribute('level')]
public str parmLevel(str _level = level)
{
level = _level;
return level;
}
}
//there is more but let's stick to those two for demo purposes
We also have this helper class
-------------------------------------------------------------
public class Helper
{
str age;
str lastName;
public str getAge()
{
age = this.removeUnneededCharacters(age);
return subStr(age, 1, 4);
}
public str getLastName()
{
return this.removeUnneededCharacters(lastName);
}
public str removeUnneededCharacters(str _line)
{
int position = strFind(_line, ':', 1, strLen(_line));
return strDel(_line, 1, position);
}
public static Helper newFromContract(IndividualDataContract _dataContract)
{
Helper helper = new Helper();
helper.age = _dataContract.parmAge();
helper.lastName = _dataContract.parmLastName()
return helper;
}
}