I think the following code works as expected and more simple. ```context``` is same as ```arg2``` in your code.

```
result.add("id", context.serialize(company.getId()));
result.add("name", context.serialize(company.getName()));
result.add("created_at", context.serialize(company.getCreatedAt()));
result.add("plan", context.serialize(company.getPlan()));
result.add("monthly_spend", new JsonPrimitive(company.getMonthlySpend()));
Map<String, Object> customData = company.getCustomData();
if (customData != null) {
    for (String key : customData.keySet()) {
        result.add(key, context.serialize(customData.get(key)));
    }
}
```