-
Notifications
You must be signed in to change notification settings - Fork 52
[Fix #1266] Marshaling improvements #1269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...mental/model/src/main/java/io/serverlessworkflow/impl/model/func/JavaModelMarshaller.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * Copyright 2020-Present The Serverless Workflow Specification Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.serverlessworkflow.impl.model.func; | ||
|
|
||
| import io.serverlessworkflow.impl.marshaller.CustomObjectMarshaller; | ||
| import io.serverlessworkflow.impl.marshaller.WorkflowInputBuffer; | ||
| import io.serverlessworkflow.impl.marshaller.WorkflowOutputBuffer; | ||
|
|
||
| public class JavaModelMarshaller implements CustomObjectMarshaller<JavaModel> { | ||
|
|
||
| @Override | ||
| public void write(WorkflowOutputBuffer buffer, JavaModel object) { | ||
| buffer.writeObject(object.asJavaObject()); | ||
| } | ||
|
|
||
| @Override | ||
| public JavaModel read(WorkflowInputBuffer buffer, Class<? extends JavaModel> clazz) { | ||
| return new JavaModel(buffer.readObject()); | ||
| } | ||
|
|
||
| @Override | ||
| public Class<JavaModel> getObjectClass() { | ||
| return JavaModel.class; | ||
| } | ||
|
|
||
| @Override | ||
| public int priority() { | ||
| return Integer.MAX_VALUE; | ||
| } | ||
| } |
63 changes: 63 additions & 0 deletions
63
...del/src/main/java/io/serverlessworkflow/impl/model/func/SerializableObjectMarshaller.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * Copyright 2020-Present The Serverless Workflow Specification Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.serverlessworkflow.impl.model.func; | ||
|
|
||
| import io.serverlessworkflow.impl.marshaller.CustomObjectMarshaller; | ||
| import io.serverlessworkflow.impl.marshaller.WorkflowInputBuffer; | ||
| import io.serverlessworkflow.impl.marshaller.WorkflowOutputBuffer; | ||
| import java.io.ByteArrayInputStream; | ||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.IOException; | ||
| import java.io.ObjectInputStream; | ||
| import java.io.ObjectOutputStream; | ||
| import java.io.Serializable; | ||
| import java.io.UncheckedIOException; | ||
|
|
||
| public class SerializableObjectMarshaller implements CustomObjectMarshaller<Serializable> { | ||
|
|
||
| @Override | ||
| public void write(WorkflowOutputBuffer buffer, Serializable object) { | ||
| try (ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); | ||
| ObjectOutputStream out = new ObjectOutputStream(bytesOut)) { | ||
| out.writeObject(object); | ||
| buffer.writeBytes(bytesOut.toByteArray()); | ||
| } catch (IOException io) { | ||
| throw new UncheckedIOException(io); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Serializable read(WorkflowInputBuffer buffer, Class<? extends Serializable> objectClass) { | ||
| try (ByteArrayInputStream bytesIn = new ByteArrayInputStream(buffer.readBytes()); | ||
| ObjectInputStream in = new ObjectInputStream(bytesIn)) { | ||
| return objectClass.cast(in.readObject()); | ||
| } catch (IOException io) { | ||
| throw new UncheckedIOException(io); | ||
| } catch (ClassNotFoundException ex) { | ||
| throw new IllegalStateException(ex); | ||
| } | ||
fjtirado marked this conversation as resolved.
Show resolved
Hide resolved
fjtirado marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| @Override | ||
| public Class<Serializable> getObjectClass() { | ||
| return Serializable.class; | ||
| } | ||
|
|
||
| @Override | ||
| public int priority() { | ||
| return Integer.MAX_VALUE; | ||
| } | ||
| } | ||
2 changes: 2 additions & 0 deletions
2
.../resources/META-INF/services/io.serverlessworkflow.impl.marshaller.CustomObjectMarshaller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| io.serverlessworkflow.impl.model.func.JavaModelMarshaller | ||
| io.serverlessworkflow.impl.model.func.SerializableObjectMarshaller |
20 changes: 20 additions & 0 deletions
20
experimental/model/src/test/java/io/serverlessworkflow/impl/model/func/Address.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /* | ||
| * Copyright 2020-Present The Serverless Workflow Specification Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.serverlessworkflow.impl.model.func; | ||
|
|
||
| import java.io.Serializable; | ||
|
|
||
| record Address(String street, int number) implements Serializable {} |
48 changes: 48 additions & 0 deletions
48
...model/src/test/java/io/serverlessworkflow/impl/model/func/JavaModelSerializationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * Copyright 2020-Present The Serverless Workflow Specification Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.serverlessworkflow.impl.model.func; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import io.serverlessworkflow.impl.marshaller.DefaultBufferFactory; | ||
| import io.serverlessworkflow.impl.marshaller.WorkflowBufferFactory; | ||
| import io.serverlessworkflow.impl.marshaller.WorkflowInputBuffer; | ||
| import io.serverlessworkflow.impl.marshaller.WorkflowOutputBuffer; | ||
| import java.io.ByteArrayInputStream; | ||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.IOException; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class JavaModelSerializationTest { | ||
|
|
||
| @Test | ||
fjtirado marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| void testSerializableJavaModel() throws IOException { | ||
| testMarshallUnMarshall( | ||
| new JavaModel(new Person("Pepe Gotera", 32, new Address("Rue del Percebe", 13)))); | ||
| } | ||
|
|
||
| private void testMarshallUnMarshall(Object object) { | ||
| WorkflowBufferFactory factory = DefaultBufferFactory.factory(); | ||
| ByteArrayOutputStream output = new ByteArrayOutputStream(); | ||
| try (WorkflowOutputBuffer writer = factory.output(output)) { | ||
| writer.writeObject(object); | ||
| } | ||
| ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray()); | ||
| try (WorkflowInputBuffer reader = factory.input(input)) { | ||
| assertThat(reader.readObject()).isEqualTo(object); | ||
| } | ||
| } | ||
| } | ||
20 changes: 20 additions & 0 deletions
20
experimental/model/src/test/java/io/serverlessworkflow/impl/model/func/Person.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /* | ||
| * Copyright 2020-Present The Serverless Workflow Specification Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.serverlessworkflow.impl.model.func; | ||
|
|
||
| import java.io.Serializable; | ||
|
|
||
| record Person(String name, int age, Address address) implements Serializable {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions
18
impl/core/src/test/java/io/serverlessworkflow/impl/marshaller/Employee.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /* | ||
| * Copyright 2020-Present The Serverless Workflow Specification Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.serverlessworkflow.impl.marshaller; | ||
|
|
||
| class Employee extends Person {} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.