diff --git a/mapping/JSONObjectMapping.cs b/mapping/JSONObjectMapping.cs index ff94bfa..3d4c4ea 100644 --- a/mapping/JSONObjectMapping.cs +++ b/mapping/JSONObjectMapping.cs @@ -32,7 +32,9 @@ namespace ln.json.mapping JSONMappingAttribute mappingAttribute = fieldInfo.GetCustomAttribute(); if ((mappingAttribute == null) || !mappingAttribute.Private) { - setters.Add(fieldInfo.Name, (object arg1, object arg2) => fieldInfo.SetValue(arg1, arg2)); + if (!fieldInfo.IsInitOnly) + setters.Add(fieldInfo.Name, (object arg1, object arg2) => fieldInfo.SetValue(arg1, arg2)); + getters.Add(fieldInfo.Name, (object arg) => fieldInfo.GetValue(arg)); types.Add(fieldInfo.Name, fieldInfo.FieldType); } @@ -42,7 +44,9 @@ namespace ln.json.mapping JSONMappingAttribute mappingAttribute = propertyInfo.GetCustomAttribute(); if ((propertyInfo.GetIndexParameters().Length == 0) && ((mappingAttribute == null) || !mappingAttribute.Private)) { - setters.Add(propertyInfo.Name, (object arg1, object arg2) => propertyInfo.SetValue(arg1, arg2)); + if (propertyInfo.CanWrite) + setters.Add(propertyInfo.Name, (object arg1, object arg2) => propertyInfo.SetValue(arg1, arg2)); + getters.Add(propertyInfo.Name, (object arg) => propertyInfo.GetValue(arg)); types.Add(propertyInfo.Name, propertyInfo.PropertyType); }