Skip to content

Commit b23c658

Browse files
committed
Use REPLACE mode when converting java string into UTF8.
1 parent 5373ddc commit b23c658

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

msgpack-core/src/main/java/org/msgpack/core/MessagePacker.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.nio.charset.CharacterCodingException;
2828
import java.nio.charset.CharsetEncoder;
2929
import java.nio.charset.CoderResult;
30+
import java.nio.charset.CodingErrorAction;
3031

3132
import static org.msgpack.core.MessagePack.Code.ARRAY16;
3233
import static org.msgpack.core.MessagePack.Code.ARRAY32;
@@ -447,7 +448,9 @@ private void packStringWithGetBytes(String s)
447448
private void prepareEncoder()
448449
{
449450
if (encoder == null) {
450-
this.encoder = MessagePack.UTF8.newEncoder();
451+
this.encoder = MessagePack.UTF8.newEncoder()
452+
.onMalformedInput(CodingErrorAction.REPLACE)
453+
.onUnmappableCharacter(CodingErrorAction.REPLACE);
451454
}
452455
encoder.reset();
453456
}

0 commit comments

Comments
 (0)