package io.agrest.parser.converter;

import javax.ws.rs.core.Response.Status;
import javax.xml.bind.DatatypeConverter;

import com.fasterxml.jackson.databind.JsonNode;
import io.agrest.AgException;

public class Base64Converter extends AbstractConverter<byte[]> {

	private static final Base64Converter instance = new Base64Converter();

	public static Base64Converter converter() {
		return instance;
	}

	@Override
	protected byte[] valueNonNull(JsonNode node) {

		if (!node.isTextual()) {
			throw new AgException(Status.BAD_REQUEST, "Expected textual value, got: " + node.asText());
		}
		try {
			// TODO: replace with Base64.Decoder when we upgrade to java 8
			return DatatypeConverter.parseBase64Binary(node.asText());
		} catch (IllegalArgumentException e) {
			throw new AgException(Status.BAD_REQUEST, "Failed to decode Base64 value: " + node.asText(), e);
		}
	}
}

@@ -71,16 +71,17 @@
 Status;%0A
+%0A
 import j
@@ -87,36 +87,20 @@
 java
-x.xml.bind.DatatypeConverter
+.util.Base64
 ;%0A%0Ai
@@ -585,37 +585,22 @@
 %0A%09%09%09
-// TODO: replace with
+return
  Base64.
 Deco
@@ -599,87 +599,27 @@
 e64.
+get
 Decoder
- when we upgrade to java 8%0A%09%09%09return DatatypeConverter.parseBase64Binary
+().decode
 (nod

Replace DatatypeConverter with Base64.Decoder