I'm doing a mapping from the database with MyBatis in Java. This is the way I am doing it and everything is working very well:
final static String GET_CONFIGURATION = "select c.codigo, c.simbolo, c.fecha, c.moneda"
+ " from pps.cuenta c"
+ " where c.cuenta_id=#{accountId}";
@Select(GET_ACCOUNT_CONFIGURATION)
@Results(value = { @Result(property = "code", javaType = String.class, column = "codigo"),
@Result(property = "symbol", javaType = String.class, column = "simbolo"),
@Result(property = "date", javaType = String.class, column = "fecha"),
@Result(property = "currency", javaType = String.class, column = "moneda")})
public Account getAccountConfiguration(@Param("accountId") final Integer accountId);
The above is mapped to an object Account
:
public class Account {
private String code;
private String symbol;
private String date;
private String currency;
/** Getter ans Setter */
...
}
In the controller I am using the mapper through a service, receiving a parameter ( accountId
):
@RequestMapping(value = SecureApiResources.Account.URI_GET_ACCOUNTS_CONFIGURATION, method = RequestMethod.GET, produces = "application/json")
public @ResponseBody AccountConfiguration getAccountConfiguration(@PathVariable(value = "accountId") Integer accountId) {
Account account = accountService.getAccountConfiguration(accountId);
...
return account;
}
So, when I try my endpoint
I get this answer:
{
"code": "COP",
"symbol": "$"
"date": "dd/MM/yyyy",
"currency": "99.999,99"
}
However, I need this structure:
{
"currency": {
"code": "COP",
"symbol": "$"
},
"formats": {
"date": "dd/MM/yyyy",
"currency": "99.999,99"
}
}
I can create a configuration
object that contains two other currency
and formats
, but this represents that I need to create these objects and assign them the corresponding values. This does not seem to be the most correct way.