mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +00:00
CE-781 Update to work without a table specified (just getting field names from the json keys)
This commit is contained in:
@ -103,13 +103,23 @@ public class JsonToQRecordAdapter
|
|||||||
{
|
{
|
||||||
QRecord record = new QRecord();
|
QRecord record = new QRecord();
|
||||||
|
|
||||||
for(QFieldMetaData field : table.getFields().values())
|
if(table == null)
|
||||||
{
|
{
|
||||||
String fieldSource = mapping == null ? field.getName() : String.valueOf(mapping.getFieldSource(field.getName()));
|
jsonObject.keys().forEachRemaining(key ->
|
||||||
// todo - so if the mapping didn't say how to map this field, does that mean we should use the default name for the field?
|
|
||||||
if(jsonObject.has(fieldSource))
|
|
||||||
{
|
{
|
||||||
record.setValue(field.getName(), (Serializable) jsonObject.get(fieldSource));
|
record.setValue(key, jsonObject.optString(key));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(QFieldMetaData field : table.getFields().values())
|
||||||
|
{
|
||||||
|
String fieldSource = mapping == null ? field.getName() : String.valueOf(mapping.getFieldSource(field.getName()));
|
||||||
|
// todo - so if the mapping didn't say how to map this field, does that mean we should use the default name for the field?
|
||||||
|
if(jsonObject.has(fieldSource))
|
||||||
|
{
|
||||||
|
record.setValue(field.getName(), (Serializable) jsonObject.get(fieldSource));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,6 +164,29 @@ class JsonToQRecordAdapterTest extends BaseTest
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
@Test
|
||||||
|
public void test_buildRecordsFromJsonWithoutTable_inputList()
|
||||||
|
{
|
||||||
|
JsonToQRecordAdapter jsonToQRecordAdapter = new JsonToQRecordAdapter();
|
||||||
|
List<QRecord> qRecords = jsonToQRecordAdapter.buildRecordsFromJson("""
|
||||||
|
[
|
||||||
|
{ "firstName":"Tyler", "last":"Samples" },
|
||||||
|
{ "firstName":"Tim", "lastName":"Chamberlain" }
|
||||||
|
]
|
||||||
|
""", null, null);
|
||||||
|
assertNotNull(qRecords);
|
||||||
|
assertEquals(2, qRecords.size());
|
||||||
|
assertEquals("Tyler", qRecords.get(0).getValue("firstName"));
|
||||||
|
assertEquals("Samples", qRecords.get(0).getValue("last"));
|
||||||
|
assertEquals("Tim", qRecords.get(1).getValue("firstName"));
|
||||||
|
assertEquals("Chamberlain", qRecords.get(1).getValue("lastName"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
Reference in New Issue
Block a user