Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JsonFields for dynamic json field names #11021

Closed
emeroad opened this issue May 16, 2024 · 0 comments · Fixed by #11022 or #11027
Closed

Add JsonFields for dynamic json field names #11021

emeroad opened this issue May 16, 2024 · 0 comments · Fixed by #11022 or #11027

Comments

@emeroad
Copy link
Member

emeroad commented May 16, 2024

Add JsonFields that can force the type of Key and Value.

Example

@Test
    public void testObjectKey() throws Exception {
        JsonFields.Builder<Key, String> builder = JsonFields.newBuilder(Key::name);  
        // default transform = Object::toString
        builder.addField(new Key("key1", 1), "value1");
        builder.addField(new Key("key2", 2), "value2");
        JsonFields<Key, String> jsonObject = builder.build();

        String s = mapper.writeValueAsString(jsonObject);
        System.out.println(s);
    }

    public record Key(String key, int value) {
        public String name() {
            return key + '-' + value;
        }
    }
{"key1-1":"value1","key2-2":"value2"}
emeroad added a commit to emeroad/pinpoint that referenced this issue May 16, 2024
emeroad added a commit to emeroad/pinpoint that referenced this issue May 16, 2024
@emeroad emeroad linked a pull request May 16, 2024 that will close this issue
emeroad added a commit to emeroad/pinpoint that referenced this issue May 16, 2024
emeroad added a commit to emeroad/pinpoint that referenced this issue May 16, 2024
emeroad added a commit that referenced this issue May 16, 2024
emeroad added a commit to emeroad/pinpoint that referenced this issue May 16, 2024
@emeroad emeroad linked a pull request May 16, 2024 that will close this issue
emeroad added a commit to emeroad/pinpoint that referenced this issue May 17, 2024
emeroad added a commit to emeroad/pinpoint that referenced this issue May 17, 2024
emeroad added a commit to emeroad/pinpoint that referenced this issue May 17, 2024
emeroad added a commit to emeroad/pinpoint that referenced this issue May 17, 2024
emeroad added a commit to emeroad/pinpoint that referenced this issue May 17, 2024
emeroad added a commit to emeroad/pinpoint that referenced this issue May 17, 2024
emeroad added a commit that referenced this issue May 17, 2024
emeroad added a commit that referenced this issue May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant