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.

[QUERY] Is it possible to serialize/deserialize EventGridEvent to/from json?

See original GitHub issue

Query/Question How can I serialize EventGridEvent to json, and then back? Please see the sample code that’s failing as follows - I think I’m not intended to be doing what I’m doing?

Unrecognized field "topic" (class com.microsoft.azure.eventgrid.models.EventGridEvent), not marked as ignorable (0 known properties: ])

It seems like EventGridEvent has the right annotations, though?

Setup (please complete the following information if applicable):

  • OS: [e.g. iOS]
  • IDE : [e.g. IntelliJ]
  • Version of the Library used

I am trying to take the raw objects out of the event log, write them to an on premise kafka queue, then read them out of the on premise kafka queue with on premise workers. The reason these things are in an on premise setup is for security compliance demands.

Deserializer snippet:

private static final ObjectMapper objectMapper = new ObjectMapper();
   
@Override
public EventGridEvent deserialize(byte[] message) throws IOException {
    return objectMapper.readValue(message, EventGridEvent.class);
}

Test snippet:

// SAMPLE EVENT: https://docs.microsoft.com/en-us/azure/event-grid/event-schema
byte[] sampleEvent = getClass().getClassLoader().getResourceAsStream("sampleEvent.json").readAllBytes();


System.out.println(new String(sampleEvent));
EventGridEvent event = deserializationSchema.deserialize(sampleEvent);
System.out.println(event.id());

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • Query Added
  • Setup information Added

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
bytesandwichcommented, Aug 5, 2020

Cool I can verify that the JacksonAdaptor works. I’m very happy with those answers to my query! Please feel free to close the ticket.

1reaction
joshfreecommented, Aug 4, 2020

Thanks for filing this issue @bytesandwich. @bsiegel could you please follow up on this track-1 inquiry?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure Event Grid event schema - Microsoft Learn
Describes the properties and schema that are present for all events. Events consist of a set of four required string properties.
Read more >
Can Json.NET serialize / deserialize to / from a stream?
The current version of Json.net does not allow you to use the accepted answer code. A current alternative is:
Read more >
JSON in Java - Baeldung
Json -io is a simple Java library to serialize/deserialize JSON. 5.1. Useful Resources.
Read more >
How to convert Java object to / from JSON (Jackson)
Quick Reference. 1.1 Convert Java object to JSON, writeValue(...) ObjectMapper mapper = new ObjectMapper(); User user = new User(); //Object ...
Read more >
Protocol Buffers, Part 3 — JSON Format | by Tomer Rothschild
... option to serialize / deserialize messages to / from JSON format. ... each of the possible types that can be packed into...
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