-
Notifications
You must be signed in to change notification settings - Fork 9
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
Do not encode booleans with XMLEncoder #306
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
Copyright 2021-2023 WeAreFrank! | ||
Copyright 2021-2024 WeAreFrank! | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
|
@@ -26,6 +26,7 @@ | |
import java.io.StringWriter; | ||
import java.io.UnsupportedEncodingException; | ||
import java.io.Writer; | ||
import java.lang.invoke.MethodHandles; | ||
import java.nio.ByteBuffer; | ||
import java.nio.CharBuffer; | ||
import java.nio.charset.CharacterCodingException; | ||
|
@@ -35,6 +36,8 @@ | |
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.w3c.dom.Node; | ||
|
||
import lombok.SneakyThrows; | ||
|
@@ -48,6 +51,7 @@ | |
* @author Jaco de Groot | ||
*/ | ||
public class MessageEncoderImpl implements MessageEncoder { | ||
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); | ||
public static final String XML_ENCODER = "XMLEncoder"; | ||
public static final String UTF8_ENCODER = "UTF-8"; | ||
public static final String CHARSET_ENCODER_PREFIX = "CHARSET-"; | ||
|
@@ -69,7 +73,10 @@ public ToStringResult toString(Object message, String charset) { | |
} else if (message instanceof String) { | ||
toStringResult = new ToStringResult((String)message, null); | ||
} else { | ||
if (message instanceof byte[]) { | ||
if (message instanceof Boolean) { | ||
toStringResult = new ToStringResult(Boolean.toString((Boolean) message), null, Boolean.class.getName()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gewoon direct returnen toch? |
||
} | ||
else if (message instanceof byte[]) { | ||
String encoding; | ||
if (charset == null) { | ||
charset = "UTF-8"; | ||
|
@@ -147,6 +154,20 @@ public <T> T toObject(Checkpoint originalCheckpoint, T messageToStub) { | |
} else { | ||
String message = originalCheckpoint.getMessage(); | ||
String encoding = originalCheckpoint.getEncoding(); | ||
String messageClassName = originalCheckpoint.getMessageClassName(); | ||
if ( (messageClassName != null) && (messageClassName.equals(Boolean.class.getName())) ) { | ||
try { | ||
Object rawResult = Boolean.valueOf(message); | ||
return (T) rawResult; | ||
Comment on lines
+160
to
+161
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Direct returnen. |
||
} catch(ClassCastException e) { | ||
if (messageToStub == null) { | ||
log.error("Could not parse message [{}] to generic type T", message); | ||
} else { | ||
log.error("Could not parse message [{}] to [{}]", message, messageToStub.getClass().getName()); | ||
} | ||
return null; | ||
} | ||
} | ||
if (encoding == null) { | ||
if (originalCheckpoint.getStreaming() == null) { | ||
return (T)message; | ||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dit is zonde, je weet immers de classname al...