public static Map parseSerializedData()

in core/src/main/java/com/amplifyframework/core/model/SerializedModel.java [132:196]


    public static Map<String, Object> parseSerializedData(Map<String, Object> serializedData, String modelName,
                                                   SchemaRegistry schemaRegistry) {
        Map<String, Object> result = new HashMap<>();
        ModelSchema modelSchema = schemaRegistry.getModelSchemaForModelClass(modelName);

        for (Map.Entry<String, ModelField> entry : modelSchema.getFields().entrySet()) {
            String key = entry.getKey();
            ModelField field = entry.getValue();
            if (!serializedData.containsKey(key)) {
                continue;
            }

            Object fieldValue = serializedData.get(key);

            if (fieldValue == null) {
                result.put(key, null);
                continue;
            }

            if (field.isModel()) {
                ModelSchema fieldModelSchema = schemaRegistry.getModelSchemaForModelClass(field.getTargetType());
                @SuppressWarnings("unchecked")
                Map<String, Object> fieldData = (Map<String, Object>) serializedData.get(key);
                if (fieldData != null) {
                    result.put(key, SerializedModel.builder()
                            .serializedData(fieldData)
                            .modelSchema(fieldModelSchema)
                            .build());
                }
            } else if (field.isCustomType()) {
                if (field.isArray()) {
                    @SuppressWarnings("unchecked")
                    List<Map<String, Object>> fieldListData = (List<Map<String, Object>>) fieldValue;
                    if (!fieldListData.isEmpty()) {
                        List<SerializedCustomType> fieldList = new ArrayList<>();
                        for (Map<String, Object> item : fieldListData) {
                            Map<String, Object> customTypeSerializedData =
                                    SerializedCustomType.parseSerializedData(
                                            item, field.getTargetType(), schemaRegistry);
                            fieldList.add(SerializedCustomType.builder()
                                    .serializedData(customTypeSerializedData)
                                    .customTypeSchema(
                                            schemaRegistry.getCustomTypeSchemaForCustomTypeClass(field.getTargetType()))
                                    .build());
                        }
                        result.put(key, fieldList);
                    }
                } else {
                    @SuppressWarnings("unchecked")
                    Map<String, Object> fieldData = (Map<String, Object>) fieldValue;
                    Map<String, Object> customTypeSerializedData =
                            SerializedCustomType.parseSerializedData(fieldData, field.getTargetType(), schemaRegistry);
                    result.put(key, SerializedCustomType.builder()
                            .serializedData(customTypeSerializedData)
                            .customTypeSchema(
                                    schemaRegistry.getCustomTypeSchemaForCustomTypeClass(field.getTargetType()))
                            .build());
                }
            } else {
                result.put(key, fieldValue);
            }
        }

        return result;
    }