I'm doing a RESTFull server with Spring MVC, the controller only returns JSON, until then blz, would my client know nothing of the domain classes and still process the requests?
I was thinking of turning JSON into an object as if it were a database table, hence I could manipulate the data, such as columns and values.
The fact is that I do not want my client to know any domain class, it just receives the information, processes, and shows the user, the user makes the changes and sends.
I created a class called DataSet, the goal is to manipulate data as if it were a table in a generic way.
example
DataSet dataset = new DataSet();
//Pode importar a partir de um pojo
/*dataset.fromPOJO(customerObject);
dataset.fromJSON(JSONString);
dataset.fromCSV(CSV);*/
dataset.setDataSource(datasource);
dataset.setTableName("Clientes");
dataset.setLimit(100);
dataset.setFetchRows(100);
dataset.getFields().add(new Field("Nome", FieldType.STRING, 100) );
dataset.getFields().add(new Field("DataNascimento", FieldType.DATE));
dataset.getFields().add(new Field("DataHoraCadastro", FieldType.DATETIME));
dataset.getFields().add(new Field("Foto", FieldType.BINARY));
dataset.getFields().add(new Field("Credito", FieldType.DOUBLE, 2));
dataset.getFields().add(new Field("Vendedor", FieldType.LOOKUP, "TABELA_PESSOA", new String[]{"id"}, new String[]{"id_vendedor"}));
dataset.getFields().add(new Field("Contatos", FieldType.DETAIL, "PESSOA_CONTATO", new String[]{"pessoa_id"}, new String[]{"id"} ));
//Adicionando registro
dataset.append();
dataset.getField("Nome").setValue("RODRIGO RODRIGUES DA COSTA");
dataset.getField("DataNascimento").setValue("06/04/1985");
dataset.getField("Credito").setValue(1765.87);
dataset.post();
dataset.append();
dataset.getField("Nome").setValue("MARIA CECILIA CABRAL RODRIGUES");
dataset.getField("DataNascimento").setValue("11/03/2011");
dataset.getField("Credito").setValue(333);
dataset.post();
System.out.println("Mostrando uma quanitdade de "+dataset.getRecordCount() );
//Monstrando todos os registros
for (Record record : dataset.getRecords()) {
System.out.println("Registro número "+record.getIndex() );
System.out.println(record.getField("Nome").getValue() );
System.out.println(record.getField("DataNascimento").getValue() );
}
I ask, have you any other way to do this? I do not want my client to know the existence of the domain class, so with the DataSet in my view it works, now has it another way?