@@ -42,9 +42,14 @@ public function normalize($node, $format = null, array $context = array())
4242 }
4343
4444 $ propertyType = $ property ->getType ();
45+
4546 $ propertyValue = $ property ->getValue ();
4647 $ propertyName = $ property ->getName ();
4748
49+ if (in_array ($ property ->getType (), array (PropertyType::REFERENCE , PropertyType::WEAKREFERENCE ))) {
50+ $ propertyValue = array_keys ($ propertyValue );
51+ }
52+
4853 $ res [$ propertyName ] = array (
4954 'type ' => PropertyType::nameFromValue ($ propertyType ),
5055 'value ' => $ propertyValue
@@ -97,22 +102,19 @@ public function denormalize($data, $class, $format = null, array $context = arra
97102 }
98103
99104 $ datum = $ this ->normalizeDatum ($ data [$ property ->getName ()]);
105+ $ typeValue = isset ($ datum ['type ' ]) ? PropertyType::valueFromName ($ datum ['type ' ]) : null ;
100106
101- if (isset ($ datum ['type ' ])) {
102- $ typeName = $ datum ['type ' ];
107+ if (isset ($ datum ['value ' ])) {
103108
104- if ($ datum ['type ' ] != $ typeName ) {
105- throw new \InvalidArgumentException (sprintf (
106- 'Cannot currently change a properties type for property "%s" (trying to change from "%s" to "%s") ' ,
107- $ property ->getPath (),
108- $ typeName , $ datum ['type ' ]
109- ));
110- }
111- }
109+ // if the type or the value is differnet, update the property
110+ if ($ datum ['value ' ] != $ property ->getValue () || $ typeValue != $ property ->getType ()) {
112111
113- if (isset ($ datum ['value ' ])) {
114- if ($ datum ['value ' ] != $ property ->getValue ()) {
115- $ property ->setValue ($ datum ['value ' ]);
112+ // setValue doesn't like being passed a null value as a type ...
113+ if ($ typeValue !== null ) {
114+ $ property ->setValue ($ datum ['value ' ], $ typeValue );
115+ } else {
116+ $ property ->setValue ($ datum ['value ' ]);
117+ }
116118 }
117119 }
118120 } catch (\Exception $ e ) {
@@ -162,7 +164,7 @@ private function normalizeDatum($value)
162164 if (is_scalar ($ value )) {
163165 return array (
164166 'value ' => $ value ,
165- 'type ' => ' String '
167+ 'type ' => null
166168 );
167169 }
168170
0 commit comments