Skip to content
Merged
Show file tree
Hide file tree
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 @@ -22,7 +22,7 @@

import java.util.Objects;

import com.adyen.serializer.ByteArrayToBase64TypeAdapter;
import com.adyen.serializer.ByteArrayToStringAdapter;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;

Expand All @@ -39,7 +39,7 @@ public class DSPublicKeyDetail {
private String directoryServerId = null;

@SerializedName("publicKey")
@JsonAdapter(ByteArrayToBase64TypeAdapter.class)
@JsonAdapter(ByteArrayToStringAdapter.class)
private byte[] publicKey = null;

public DSPublicKeyDetail brand(String brand) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/adyen/model/checkout/ThreeDSecureData.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import java.io.IOException;
import java.util.Objects;

import com.adyen.serializer.ByteArrayToStringAdapter;
import com.google.gson.TypeAdapter;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
Expand All @@ -37,6 +39,7 @@ public class ThreeDSecureData {
@SerializedName("authenticationResponse")
private AuthenticationResponseEnum authenticationResponse = null;
@SerializedName("cavv")
@JsonAdapter(ByteArrayToStringAdapter.class)
private byte[] cavv = null;
@SerializedName("cavvAlgorithm")
private String cavvAlgorithm = null;
Expand All @@ -47,6 +50,7 @@ public class ThreeDSecureData {
@SerializedName("threeDSVersion")
private String threeDSVersion = null;
@SerializedName("xid")
@JsonAdapter(ByteArrayToStringAdapter.class)
private byte[] xid = null;
@SerializedName("dsTransID")
private String dsTransID = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import org.apache.commons.codec.binary.Base64;

import java.lang.reflect.Type;

public class ByteArrayToBase64TypeAdapter implements JsonSerializer<byte[]>, JsonDeserializer<byte[]> {
public class ByteArrayToStringAdapter implements JsonSerializer<byte[]>, JsonDeserializer<byte[]> {
public byte[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
return Base64.decodeBase64(json.getAsString());
return json.getAsString().getBytes();
}

public JsonElement serialize(byte[] src, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(Base64.encodeBase64String(src));
return new JsonPrimitive(new String(src));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Java API Library
*
* Copyright (c) 2019 Adyen B.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*/
package com.adyen.serializer;

import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import org.apache.commons.codec.binary.Base64;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

@RunWith(MockitoJUnitRunner.class)
public class ByteArrayToStringAdapterTest {

@Test
public void testSerialize() {
ByteArrayToStringAdapter adapter = new ByteArrayToStringAdapter();
byte[] base64Bytes = Base64.encodeBase64("Bytes-To-Be-Encoded".getBytes());

JsonElement serializedElement = adapter.serialize(base64Bytes, null, null);
assertEquals("Qnl0ZXMtVG8tQmUtRW5jb2RlZA==", serializedElement.getAsString());
}

@Test
public void testDeserialize() {
ByteArrayToStringAdapter adapter = new ByteArrayToStringAdapter();
byte[] base64Bytes = Base64.encodeBase64("Bytes-To-Be-Encoded".getBytes());

JsonElement element = new JsonPrimitive("Qnl0ZXMtVG8tQmUtRW5jb2RlZA==");
byte[] deserializedBytes = adapter.deserialize(element, null, null);

assertArrayEquals(deserializedBytes, base64Bytes);
}
}