You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@olingo.apache.org by "Frederic Souchu (JIRA)" <ji...@apache.org> on 2015/04/01 17:08:54 UTC
[jira] [Updated] (OLINGO-615) Unable to serialize custom enum type
[ https://issues.apache.org/jira/browse/OLINGO-615?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Frederic Souchu updated OLINGO-615:
-----------------------------------
Description:
The serializer code path is missing a fallback for enumerated values, similar to collection or complex types.
(exception trace below)
How to reproduce:
- declare an enumerated field in EDM
- add enum value in entity set:
{code:java}
EntitySet entitySet = new EntitySetImpl();
entitySet.getEntities().add(new EntityImpl()
.addProperty(new PropertyImpl(null, "ID", ValueType.PRIMITIVE, 4864))
.addProperty(new PropertyImpl("company.com.MyEnum", "EnumField", ValueType.ENUM, 2)));
{code}
- call serializer from servlet, an exception is raised: Property type not yet supported!
What is happening (as far as I can tell):
- EdmTypeInfo.java primitiveType member is null (as expected)
- enumType is correctly set to my custom enum type
- ODataJsonSerializer.java correctly evaluates the type as 'not primitive', tries various fallback scenario to throw an exception.
>> The appriopriate writePropertyValue method (where enum serialization code is) is never called!!
{code:java}
private void writePropertyValue(final EdmProperty edmProperty,
final Property property, final Set<List<String>> selectedPaths,
final JsonGenerator json) throws IOException, SerializerException {
try {
if (edmProperty.isPrimitive()) {
/* primitive handling code not executed for an enum !! */
} else if (edmProperty.isCollection()) {
writeComplexCollection((EdmComplexType) edmProperty.getType(), property, selectedPaths, json);
} else if (property.isLinkedComplex()) {
writeComplexValue((EdmComplexType) edmProperty.getType(), property.asLinkedComplex().getValue(),
selectedPaths, json);
} else if (property.isComplex()) {
writeComplexValue((EdmComplexType) edmProperty.getType(), property.asComplex(), selectedPaths, json);
} else {
throw new SerializerException("Property type not yet supported!",
SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName());
}
} catch (final EdmPrimitiveTypeException e) {
/* error msg mgt */
}
}
{code}
Note: setting the value using:
{code:java}
.addProperty(new PropertyImpl("company.com.MyEnum", "EnumField", ValueType.PRIMITIVE, 2))
{code}
or
{code:java}
.addProperty(new PropertyImpl(null, "EnumField", ValueType.PRIMITIVE, 2))
{code}
yields the same exception:
{code:text}
ODataJsonSerializer.writePropertyValue(EdmProperty, Property, Set<List<String>>, JsonGenerator) line: 327
ODataJsonSerializer.writeProperty(EdmProperty, Property, Set<List<String>>, JsonGenerator) line: 299
ODataJsonSerializer.writeProperties(EdmStructuredType, List<Property>, SelectOption, JsonGenerator) line: 238
ODataJsonSerializer.writeEntity(EdmEntityType, Entity, ContextURL, ExpandOption, SelectOption, JsonGenerator) line: 222
ODataJsonSerializer.writeEntitySet(EdmEntityType, EntitySet, ExpandOption, SelectOption, JsonGenerator) line: 197
ODataJsonSerializer.entityCollection(EdmEntityType, EntitySet, EntityCollectionSerializerOptions) line: 153
TransactionProcessor.readEntityCollection(ODataRequest, ODataResponse, UriInfo, ContentType) line: 132
ODataHandler.handleEntityDispatching(ODataRequest, ODataResponse, boolean, boolean, boolean) line: 597
ODataHandler.handleEntityDispatching(ODataRequest, ODataResponse, UriResourcePartTyped) line: 583
ODataHandler.handleResourceDispatching(ODataRequest, ODataResponse) line: 251
ODataHandler.processInternal(ODataRequest, ODataResponse) line: 192
ODataHandler.process(ODataRequest) line: 111
ODataHttpHandlerImpl.process(HttpServletRequest, HttpServletResponse) line: 66
TransactionJournalRestService.customerJournal() line: 95 (out of synch)
TransactionJournalRestService$Proxy$_$$_WeldClientProxy.customerJournal() line: not available
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25
Method.invoke(Object, Object...) line: 597
MethodInjectorImpl.invoke(HttpRequest, HttpResponse, Object) line: 167
ResourceMethod.invokeOnTarget(HttpRequest, HttpResponse, Object) line: 269
ResourceMethod.invoke(HttpRequest, HttpResponse, Object) line: 227
ResourceMethod.invoke(HttpRequest, HttpResponse) line: 216
SynchronousDispatcher.getResponse(HttpRequest, HttpResponse, ResourceInvoker) line: 542
SynchronousDispatcher.invoke(HttpRequest, HttpResponse, ResourceInvoker) line: 524
SynchronousDispatcher.invoke(HttpRequest, HttpResponse) line: 126
ServletContainerDispatcher.service(String, HttpServletRequest, HttpServletResponse, boolean) line: 208
HttpServlet30Dispatcher(HttpServletDispatcher).service(String, HttpServletRequest, HttpServletResponse) line: 55
HttpServlet30Dispatcher(HttpServletDispatcher).service(HttpServletRequest, HttpServletResponse) line: 50
HttpServlet30Dispatcher(HttpServlet).service(ServletRequest, ServletResponse) line: 847
ApplicationFilterChain.internalDoFilter(ServletRequest, ServletResponse) line: 295
ApplicationFilterChain.doFilter(ServletRequest, ServletResponse) line: 214
StandardWrapperValve.invoke(Request, Response) line: 231
StandardContextValve.invoke(Request, Response) line: 149
WebNonTxEmCloserValve.invoke(Request, Response) line: 50
WebNonTxEmCloserValve.invoke(Request, Response) line: 50
SecurityContextAssociationValve.invoke(Request, Response) line: 169
StandardHostValve.invoke(Request, Response) line: 145
ErrorReportValve.invoke(Request, Response) line: 97
StandardEngineValve.invoke(Request, Response) line: 102
CoyoteAdapter.service(Request, Response) line: 344
Http11Processor.process(Socket) line: 856
Http11Protocol$Http11ConnectionHandler.process(Socket) line: 653
JIoEndpoint$Worker.run() line: 926
Thread.run() line: 662
{code}
was:
The serializer code path is missing a fallback for enumerated values, similar to collection or complex types.
How to reproduce:
- declare an enumerated field in EDM
- add enum value in entity set:
{code:java}
EntitySet entitySet = new EntitySetImpl();
entitySet.getEntities().add(new EntityImpl()
.addProperty(new PropertyImpl(null, "ID", ValueType.PRIMITIVE, 4864))
.addProperty(new PropertyImpl(null, "company.com.MyEnum", ValueType.ENUM, 2)));
{code}
- call serializer from servlet, an exception is raised: Property type not yet supported!
What is happening:
- EdmTypeInfo.java primitiveType member is null (as expected)
- enumType is correctly set to my custom enum type
- ODataJsonSerializer.java correctly evaluates the type as 'not primitive' and does not call the appriopriate writePropertyValue method (where enum serialization code is!!)
{code:java}
private void writePropertyValue(final EdmProperty edmProperty,
final Property property, final Set<List<String>> selectedPaths,
final JsonGenerator json) throws IOException, SerializerException {
try {
if (edmProperty.isPrimitive()) {
/* primitive handling code not executed for an enum !! */
} else if (edmProperty.isCollection()) {
writeComplexCollection((EdmComplexType) edmProperty.getType(), property, selectedPaths, json);
} else if (property.isLinkedComplex()) {
writeComplexValue((EdmComplexType) edmProperty.getType(), property.asLinkedComplex().getValue(),
selectedPaths, json);
} else if (property.isComplex()) {
writeComplexValue((EdmComplexType) edmProperty.getType(), property.asComplex(), selectedPaths, json);
} else {
throw new SerializerException("Property type not yet supported!",
SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName());
}
} catch (final EdmPrimitiveTypeException e) {
/* error msg mgt */
}
}
{code}
> Unable to serialize custom enum type
> ------------------------------------
>
> Key: OLINGO-615
> URL: https://issues.apache.org/jira/browse/OLINGO-615
> Project: Olingo
> Issue Type: Bug
> Components: odata4-server
> Affects Versions: (Java) V4 4.0.0-beta-02
> Reporter: Frederic Souchu
>
> The serializer code path is missing a fallback for enumerated values, similar to collection or complex types.
> (exception trace below)
> How to reproduce:
> - declare an enumerated field in EDM
> - add enum value in entity set:
> {code:java}
> EntitySet entitySet = new EntitySetImpl();
> entitySet.getEntities().add(new EntityImpl()
> .addProperty(new PropertyImpl(null, "ID", ValueType.PRIMITIVE, 4864))
> .addProperty(new PropertyImpl("company.com.MyEnum", "EnumField", ValueType.ENUM, 2)));
> {code}
> - call serializer from servlet, an exception is raised: Property type not yet supported!
> What is happening (as far as I can tell):
> - EdmTypeInfo.java primitiveType member is null (as expected)
> - enumType is correctly set to my custom enum type
> - ODataJsonSerializer.java correctly evaluates the type as 'not primitive', tries various fallback scenario to throw an exception.
> >> The appriopriate writePropertyValue method (where enum serialization code is) is never called!!
> {code:java}
> private void writePropertyValue(final EdmProperty edmProperty,
> final Property property, final Set<List<String>> selectedPaths,
> final JsonGenerator json) throws IOException, SerializerException {
> try {
> if (edmProperty.isPrimitive()) {
> /* primitive handling code not executed for an enum !! */
> } else if (edmProperty.isCollection()) {
> writeComplexCollection((EdmComplexType) edmProperty.getType(), property, selectedPaths, json);
> } else if (property.isLinkedComplex()) {
> writeComplexValue((EdmComplexType) edmProperty.getType(), property.asLinkedComplex().getValue(),
> selectedPaths, json);
> } else if (property.isComplex()) {
> writeComplexValue((EdmComplexType) edmProperty.getType(), property.asComplex(), selectedPaths, json);
> } else {
> throw new SerializerException("Property type not yet supported!",
> SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName());
> }
> } catch (final EdmPrimitiveTypeException e) {
> /* error msg mgt */
> }
> }
> {code}
> Note: setting the value using:
> {code:java}
> .addProperty(new PropertyImpl("company.com.MyEnum", "EnumField", ValueType.PRIMITIVE, 2))
> {code}
> or
> {code:java}
> .addProperty(new PropertyImpl(null, "EnumField", ValueType.PRIMITIVE, 2))
> {code}
> yields the same exception:
> {code:text}
> ODataJsonSerializer.writePropertyValue(EdmProperty, Property, Set<List<String>>, JsonGenerator) line: 327
> ODataJsonSerializer.writeProperty(EdmProperty, Property, Set<List<String>>, JsonGenerator) line: 299
> ODataJsonSerializer.writeProperties(EdmStructuredType, List<Property>, SelectOption, JsonGenerator) line: 238
> ODataJsonSerializer.writeEntity(EdmEntityType, Entity, ContextURL, ExpandOption, SelectOption, JsonGenerator) line: 222
> ODataJsonSerializer.writeEntitySet(EdmEntityType, EntitySet, ExpandOption, SelectOption, JsonGenerator) line: 197
> ODataJsonSerializer.entityCollection(EdmEntityType, EntitySet, EntityCollectionSerializerOptions) line: 153
> TransactionProcessor.readEntityCollection(ODataRequest, ODataResponse, UriInfo, ContentType) line: 132
> ODataHandler.handleEntityDispatching(ODataRequest, ODataResponse, boolean, boolean, boolean) line: 597
> ODataHandler.handleEntityDispatching(ODataRequest, ODataResponse, UriResourcePartTyped) line: 583
> ODataHandler.handleResourceDispatching(ODataRequest, ODataResponse) line: 251
> ODataHandler.processInternal(ODataRequest, ODataResponse) line: 192
> ODataHandler.process(ODataRequest) line: 111
> ODataHttpHandlerImpl.process(HttpServletRequest, HttpServletResponse) line: 66
> TransactionJournalRestService.customerJournal() line: 95 (out of synch)
> TransactionJournalRestService$Proxy$_$$_WeldClientProxy.customerJournal() line: not available
> NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]
> NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39
> DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25
> Method.invoke(Object, Object...) line: 597
> MethodInjectorImpl.invoke(HttpRequest, HttpResponse, Object) line: 167
> ResourceMethod.invokeOnTarget(HttpRequest, HttpResponse, Object) line: 269
> ResourceMethod.invoke(HttpRequest, HttpResponse, Object) line: 227
> ResourceMethod.invoke(HttpRequest, HttpResponse) line: 216
> SynchronousDispatcher.getResponse(HttpRequest, HttpResponse, ResourceInvoker) line: 542
> SynchronousDispatcher.invoke(HttpRequest, HttpResponse, ResourceInvoker) line: 524
> SynchronousDispatcher.invoke(HttpRequest, HttpResponse) line: 126
> ServletContainerDispatcher.service(String, HttpServletRequest, HttpServletResponse, boolean) line: 208
> HttpServlet30Dispatcher(HttpServletDispatcher).service(String, HttpServletRequest, HttpServletResponse) line: 55
> HttpServlet30Dispatcher(HttpServletDispatcher).service(HttpServletRequest, HttpServletResponse) line: 50
> HttpServlet30Dispatcher(HttpServlet).service(ServletRequest, ServletResponse) line: 847
> ApplicationFilterChain.internalDoFilter(ServletRequest, ServletResponse) line: 295
> ApplicationFilterChain.doFilter(ServletRequest, ServletResponse) line: 214
> StandardWrapperValve.invoke(Request, Response) line: 231
> StandardContextValve.invoke(Request, Response) line: 149
> WebNonTxEmCloserValve.invoke(Request, Response) line: 50
> WebNonTxEmCloserValve.invoke(Request, Response) line: 50
> SecurityContextAssociationValve.invoke(Request, Response) line: 169
> StandardHostValve.invoke(Request, Response) line: 145
> ErrorReportValve.invoke(Request, Response) line: 97
> StandardEngineValve.invoke(Request, Response) line: 102
> CoyoteAdapter.service(Request, Response) line: 344
> Http11Processor.process(Socket) line: 856
> Http11Protocol$Http11ConnectionHandler.process(Socket) line: 653
> JIoEndpoint$Worker.run() line: 926
> Thread.run() line: 662
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)