exceptionfactory commented on a change in pull request #5145:
URL: https://github.com/apache/nifi/pull/5145#discussion_r680163592



##########
File path: 
nifi-registry/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jaxb/JAXBSerializer.java
##########
@@ -88,9 +98,15 @@ public T deserialize(final InputStream input) throws 
SerializationException {
         try {
             // Consume the header bytes.
             readDataModelVersion(input);
+
+            XMLStreamReader streamReader = 
XMLInputFactory.newInstance().createXMLStreamReader(input);
+
             final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
-            return (T) unmarshaller.unmarshal(input);
-        } catch (JAXBException e) {
+            JAXBElement<T> jaxbElement = unmarshaller.unmarshal(streamReader, 
clazz);
+            T deserializedObject = jaxbElement.getValue();
+
+            return deserializedObject;

Review comment:
       This could be collapsed into a single line.
   ```suggestion
               return jaxbElement.getValue();
   ```

##########
File path: nifi-registry/nifi-registry-core/nifi-registry-data-model/pom.xml
##########
@@ -33,6 +33,11 @@
             <groupId>javax.ws.rs</groupId>
             <artifactId>javax.ws.rs-api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.nifi</groupId>
+            <artifactId>nifi-api</artifactId>
+            <version>1.14.0-SNAPSHOT</version>

Review comment:
       This should be updated to 1.15.0-SNAPSHOT to match the current main 
branch.
   ```suggestion
               <version>1.15.0-SNAPSHOT</version>
   ```

##########
File path: 
nifi-registry/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jaxb/JAXBSerializer.java
##########
@@ -88,9 +98,15 @@ public T deserialize(final InputStream input) throws 
SerializationException {
         try {
             // Consume the header bytes.
             readDataModelVersion(input);
+
+            XMLStreamReader streamReader = 
XMLInputFactory.newInstance().createXMLStreamReader(input);

Review comment:
       Is it necessary to create an `XMLStreamReader` as opposed to wrapping 
the input in a `StreamSource`?

##########
File path: 
nifi-registry/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/serialization/jaxb/JAXBSerializer.java
##########
@@ -73,8 +79,12 @@ public void serialize(final int dataModelVersion, final T t, 
final OutputStream
         try {
             final Marshaller marshaller = jaxbContext.createMarshaller();
             marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
-            marshaller.marshal(t, out);
-        } catch (JAXBException e) {
+
+            String className = clazz.getSimpleName();
+            String tagName = Character.toLowerCase(className.charAt(0)) + 
className.substring(1);
+
+            marshaller.marshal(new JAXBElement<>(new QName(tagName), clazz, 
t), out);

Review comment:
       This approach seems like it should work for most cases given that 
current `XmlRootElement` annotations that specify a `name` attribute follow 
this pattern. However, what do you think about making this specific to 
`VersionedProcessGroup`? So if this class is an instance of 
`VersionedProcessGroup`, then use this approach, otherwise use the current 
`marshal()` call.
   
   Another alternative could be using reflection to see whether the class has 
the `XmlRootElement` annotation.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to