Skip to content

Commit

Permalink
fix bug: 'Class not found when unmarshalling: channel.helper.pipe.Map…
Browse files Browse the repository at this point in the history
…Wrapper'
  • Loading branch information
jrfeng committed Aug 9, 2020
1 parent 0cc6283 commit ee6c77d
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions pipe/src/main/java/channel/helper/pipe/MessengerPipe.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package channel.helper.pipe;

import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
Expand Down Expand Up @@ -55,6 +56,7 @@
*/
public class MessengerPipe extends Handler implements Emitter {
private static final String TAG = "MessengerPipe";
private static final String KEY_MAP_WRAPPER = "map_wrapper";

private Messenger mMessenger;
private Dispatcher mDispatcher;
Expand Down Expand Up @@ -89,7 +91,11 @@ public void handleMessage(@NonNull Message msg) {
@Override
public void emit(Map<String, Object> data) {
Message message = Message.obtain();
message.obj = new MapWrapper(data);

Bundle bundle = new Bundle();
bundle.putParcelable(KEY_MAP_WRAPPER, new MapWrapper(data));

message.setData(bundle);

try {
mMessenger.send(message);
Expand All @@ -99,18 +105,21 @@ public void emit(Map<String, Object> data) {
}

private Map<String, Object> getData(Message dataWrapper) {
if (dataWrapper.obj == null) {
Bundle bundle = dataWrapper.getData();

if (bundle == null) {
Log.d(TAG, "dataWrapper is empty.");
return new HashMap<>();
}

if (!(dataWrapper.obj instanceof MapWrapper)) {
bundle.setClassLoader(MapWrapper.class.getClassLoader());
MapWrapper mapWrapper = bundle.getParcelable(KEY_MAP_WRAPPER);

if (mapWrapper == null) {
Log.d(TAG, "dataWrapper is empty.");
return new HashMap<>();
}

MapWrapper mapWrapper = (MapWrapper) dataWrapper.obj;

return mapWrapper.getMap();
}

Expand Down

0 comments on commit ee6c77d

Please sign in to comment.