Skip to content
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

Resolved #513. #514

Merged
merged 1 commit into from
Dec 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,57 @@
import java.io.IOException;


/**
* A deserialization schema that deserializes a JSON object into an object of the target type.
* The JSON object is expected to be in snake_case format.
*
* @param <T> The type of the deserialized object.
*/
public class SnakeCaseJsonDeserializationSchema<T> implements DeserializationSchema<T> {
private final Class<T> targetType;
private final ObjectMapper objectMapper;

/**
* Constructor. Sets the target type of the deserialized object.
*
* @param targetType The type of the deserialized object.
*/
public SnakeCaseJsonDeserializationSchema(Class<T> targetType) {
this.targetType = targetType;
this.objectMapper = new ObjectMapper();
this.objectMapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
}

/**
* Deserializes the message into an object of the target type.
*
* @param message The message to be deserialized.
*
* @return The deserialized object.
*/
@Override
public T deserialize(byte[] message) throws IOException {
return objectMapper.readValue(message, targetType);
}

/**
* Method to decide whether the element signals the end of the stream. If true is
* returned the element won't be emitted.
*
* @param nextElement The element to test for the end-of-stream signal.
*
* @return True, if the element signals end of stream, false otherwise.
*/
@Override
public boolean isEndOfStream(T nextElement) {
return false;
}

/**
* Gets the type information of the produced type.
*
* @return The type information.
*/
@Override
public TypeInformation<T> getProducedType() {
return TypeInformation.of(targetType);
Expand Down