You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@olingo.apache.org by "Elliott, Anthony (LNG-RDU)" <an...@lexisnexis.com> on 2014/08/13 23:05:51 UTC

Fix to bind JSON enums and linked-complex types

Hi,

I merged my local version of Olingo 4 with the official upstream version over the past couple days and ran into an issue where my Enums and Collections of Linked-Complex types weren't being parsed from JSON into the correct Java objects.

This should be fixed (worked for me anyways) by adding two clauses inside AbstractODataBinder.getODataValue()

// existing code
else if (valuable.isEnum()) {
          String str = valuable.getValue().toString();
          value = new ODataEnumValueImpl(type.getFullQualifiedNameAsString(), str);
        } else if (valuable.isLinkedComplex()) {
            @SuppressWarnings("unchecked")
            ODataComplexValue<CommonODataProperty> cValue =
                    (ODataComplexValue<CommonODataProperty>) client.getObjectFactory()
                            .newComplexValue(type == null ? null : type.toString());

            LinkedComplexValue lcValue = valuable.asLinkedComplex();
            List<Property> properties = lcValue.getValue();
            for (Property property : properties) {
                ODataProperty insideProperty = getODataProperty(null, property);
                cValue.add(insideProperty);
            }
            value = cValue;
        }

// existing code