question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for !binary tag

See original GitHub issue

Hi, I have to read yaml files with tags like this: !binary "SSBMaWtlIGJlYW5zIQ==" This tag seems to be YAML standard, a Base64 encoded string. I have already managed to read this as String by insert reader.getConfig().setClassTag("binary", String.class);, and doing a base64 decode later, but the problem is the value on this position is not always Base64 encoded, it’s also a simple string.

Can you add internal support for the !binary tag, or hint me how to write a proper proxy class?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
NathanSweetcommented, Feb 6, 2019

Or a little shorter, use BinarySerializer instead of the BinaryString placeholder:

static public class Test {
	public String s1, s2;

	public String toString () {
		return s1 + ", " + s2;
	}
}

static public class BinarySerializer implements ScalarSerializer<String> {
	public String write (String object) throws YamlException {
		return Base64.getEncoder().encodeToString(object.getBytes());
	}

	public String read (String value) throws YamlException {
		return new String(Base64.getDecoder().decode(value));
	}
}

static public void main (String[] args) throws Exception {
	YamlConfig c = new YamlConfig();
	c.setClassTag("binary", BinarySerializer.class);
	c.setScalarSerializer(BinarySerializer.class, new BinarySerializer());
	YamlReader r = new YamlReader("{ s1: !binary SSBMaWtlIGJlYW5zIQ==, s2: I Like beans! }", c);
	System.out.println(r.read(Test.class));
}
1reaction
NathanSweetcommented, Feb 6, 2019

Ah, gotcha. You can do this:

static public class Test {
	public String s1, s2;

	public String toString () {
		return s1 + ", " + s2;
	}
}

static public class BinaryString {
}

static public class BinarySerializer implements ScalarSerializer<String> {
	public String write (String object) throws YamlException {
		return Base64.getEncoder().encodeToString(object.getBytes());
	}

	public String read (String value) throws YamlException {
		return new String(Base64.getDecoder().decode(value));
	}
}

static public void main (String[] args) throws Exception {
	YamlConfig c = new YamlConfig();
	c.setClassTag("binary", BinaryString.class);
	c.setScalarSerializer(BinaryString.class, new BinarySerializer());
	YamlReader r = new YamlReader("{ s1: !binary SSBMaWtlIGJlYW5zIQ==, s2: I Like beans! }", c);
	System.out.println(r.read(Test.class));
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Enabling binary support using the API Gateway console
The section explains how to enable binary support using the API Gateway console. As an example, we use an API that is integrated...
Read more >
Problem with binary tag on tag logging WinCC 7.0 - 119329
Hi friends, I've been trying to create a Binary Tag Tag logging on and i have success, but i can not monitoring this...
Read more >
OUD 11.1.2.3.x: A "binary" Tag is Being ... - My Oracle Support
After upgrading OUD from 11.1.2.2.0 to 11.1.2.3.0, the custom attribute used for OpenSSH Public Key now contains a ";binary::" tag in the name ......
Read more >
NBT - wiki.vg
The Named Binary Tag (NBT) file format is an extremely simple and efficient structured binary format used by the Minecraft game for a...
Read more >
javascript - Populating an input type tag with a Binary response
Since you don't show how you made this request, we can't help you much here. Then you'll be able to convert either of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found