Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-31890

Fix unable to serialize DocumentValidationException

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 2021.35
    • Fix Version/s: 2021.x, 2023.x
    • Component/s: Rest API

      Description

      Steps to reproduce

      • Set in your nuxeo.conf the following property:
        org.nuxeo.rest.stack.enable=true
        
      • Configure a new document type with a constraint, see contributions and schema below:
        <component name="org.nuxeo.test.validation">
        
          <extension target="org.nuxeo.ecm.core.schema.TypeService" point="schema">
            <schema name="validation" src="validation.xsd" prefix="validation" />
          </extension>
        
          <extension target="org.nuxeo.ecm.core.schema.TypeService" point="doctype">
            <doctype name="Validation" extends="File">
              <schema name="validation" />
            </doctype>
          </extension>
        
          <extension target="org.nuxeo.ecm.core.api.DocumentValidationService" point="activations">
            <validation context="createDocument" activated="true" />
            <validation context="saveDocument" activated="true" />
            <validation context="importDocument" activated="true" />
          </extension>
        
        </component>
        
        <?xml version="1.0"?>
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
                   xmlns:nxv="http://nuxeo.com/schemas/validation"
                   xmlns:nxsv="http://www.nuxeo.org/ecm/schemas/core/validation/"
                   targetNamespace="http://nuxeo.com/schemas/validation">
        
          <xs:element name="user" type="nxv:user"/>
        
          <xs:complexType name="user">
            <xs:sequence>
              <xs:element name="name" nillable="false" nxsv:nillable="false">
                <xs:simpleType>
                  <xs:restriction base="xs:string">
                    <xs:pattern value=".*\S.*"/>
                  </xs:restriction>
                </xs:simpleType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        
        </xs:schema>
        
      • Create a document with a constraint violation (do not set the accepted mime type):
        curl -uAdministrator:Administrator -H 'Content-Type:application/json' -XPOST http://localhost:8080/nuxeo/api/v1/path/ -d '{"entity-type":"document","type":"Validation","name":"validation","properties":{"validation:user":{"name":"   "}}}'
        

      Actual result

      The server return an html error content.

      We can observe in the nuxeo server logs the error below:

      2023-05-19T15:34:36,469 ERROR [http-nio-0.0.0.0-8080-exec-4] [org.nuxeo.ecm.platform.web.common.exceptionhandling.DefaultNuxeoExceptionHandler] com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.nuxeo.ecm.core.api.validation.DocumentValidationReport and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.nuxeo.ecm.core.api.validation.DocumentValidationException["report"])
      com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.nuxeo.ecm.core.api.validation.DocumentValidationReport and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.nuxeo.ecm.core.api.validation.DocumentValidationException["report"])
              at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:77) ~[jackson-databind-2.12.7.1.jar:2.12.7.1]
              at com.fasterxml.jackson.databind.SerializerProvider.reportBadDefinition(SerializerProvider.java:1276) ~[jackson-databind-2.12.7.1.jar:2.12.7.1]
              at com.fasterxml.jackson.databind.DatabindContext.reportBadDefinition(DatabindContext.java:400) ~[jackson-databind-2.12.7.1.jar:2.12.7.1]
              at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:71) ~[jackson-databind-2.12.7.1.jar:2.12.7.1]
              at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:33) ~[jackson-databind-2.12.7.1.jar:2.12.7.1]
              at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:728) ~[jackson-databind-2.12.7.1.jar:2.12.7.1]
              at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:770) ~[jackson-databind-2.12.7.1.jar:2.12.7.1]
              at org.nuxeo.ecm.webengine.JsonFactoryManagerImpl$ThrowableSerializer.serializeFields(JsonFactoryManagerImpl.java:64) ~[nuxeo-webengine-core-2021.35.4.jar:?]
              at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:178) ~[jackson-databind-2.12.7.1.jar:2.12.7.1]
              at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480) ~[jackson-databind-2.12.7.1.jar:2.12.7.1]
              at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319) ~[jackson-databind-2.12.7.1.jar:2.12.7.1]
              at com.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:3126) ~[jackson-databind-2.12.7.1.jar:2.12.7.1]
              at com.fasterxml.jackson.core.base.GeneratorBase.writeObject(GeneratorBase.java:388) ~[jackson-core-2.12.7.jar:2.12.7]
              at com.fasterxml.jackson.core.JsonGenerator.writeObjectField(JsonGenerator.java:2332) ~[jackson-core-2.12.7.jar:2.12.7]
              at org.nuxeo.ecm.webengine.app.JsonWebengineWriter.writeException(JsonWebengineWriter.java:101) ~[nuxeo-webengine-core-2021.35.4.jar:?]
              at org.nuxeo.ecm.webengine.app.JsonWebengineWriter.writeException(JsonWebengineWriter.java:87) ~[nuxeo-webengine-core-2021.35.4.jar:?]
              at org.nuxeo.ecm.webengine.app.JsonWebengineWriter.writeException(JsonWebengineWriter.java:79) ~[nuxeo-webengine-core-2021.35.4.jar:?]
              at org.nuxeo.ecm.webengine.app.JsonNuxeoExceptionWriter.writeTo(JsonNuxeoExceptionWriter.java:57) ~[nuxeo-webengine-core-2021.35.4.jar:?]
              at org.nuxeo.ecm.webengine.app.JsonNuxeoExceptionWriter.writeTo(JsonNuxeoExceptionWriter.java:39) ~[nuxeo-webengine-core-2021.35.4.jar:?]
              at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:302) ~[jersey-server-1.19.4.jar:1.19.4]
              at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1510) ~[jersey-server-1.19.4.jar:1.19.4]
              at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419) ~[jersey-server-1.19.4.jar:1.19.4]
              at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409) ~[jersey-server-1.19.4.jar:1.19.4]
              at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409) ~[jersey-servlet-1.19.4.jar:1.19.4]
              at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558) ~[jersey-servlet-1.19.4.jar:1.19.4]
              at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733) ~[jersey-servlet-1.19.4.jar:1.19.4]
              at org.nuxeo.ecm.webengine.app.jersey.WebEngineServlet.containerService(WebEngineServlet.java:62) ~[nuxeo-webengine-core-2021.35.4.jar:?]
              at org.nuxeo.ecm.webengine.app.jersey.WebEngineServlet.service(WebEngineServlet.java:46) ~[nuxeo-webengine-core-2021.35.4.jar:?]
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:596) ~[servlet-api.jar:4.0.FR]
      

      Expected result

      The server should write the exception like any others such as describe here.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              kleturc Kevin Leturc
              Participants:
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: