Skip to content

Commit

Permalink
Missing bits
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Oct 8, 2024
1 parent 22be25d commit 114fa2e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@
import io.vertx.codegen.annotations.VertxGen;

import java.util.Arrays;
import java.util.Base64;

/**
* @author <a href="mailto:[email protected]">Julien Viet</a>
*/
@DataObject
public interface Buffer {

static Buffer fromJson(String base64) {
Base64.Decoder decoder = Base64.getUrlDecoder();
byte[] bytes = decoder.decode(base64);
return buffer(bytes);
}

@GenIgnore(GenIgnore.PERMITTED_TYPE)
static Buffer buffer(byte[] bytes) {
return new Buffer() {
Expand All @@ -32,4 +39,9 @@ public boolean equals(Object obj) {

@GenIgnore(GenIgnore.PERMITTED_TYPE)
byte[] getBytes();

default String toJson() {
Base64.Encoder encoder = Base64.getUrlEncoder().withoutPadding();
return encoder.encodeToString(getBytes());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -960,8 +960,9 @@ public void testBuffer() throws Exception {

PropertyInfo prop = model.getPropertyMap().get("buffer");
assertNotNull(prop);
assertFalse(prop.getType().getDataObject().isDeserializable());
assertFalse(prop.getType().getDataObject().isSerializable());
assertNull(prop.getType().getDataObject().getJsonType());
assertTrue(prop.getType().getDataObject().isDeserializable());
assertTrue(prop.getType().getDataObject().isSerializable());
assertNotNull(prop.getType().getDataObject().getJsonType());
assertEquals("java.lang.String", prop.getType().getDataObject().getJsonType().getName());
}
}

0 comments on commit 114fa2e

Please sign in to comment.