GithubHelp home page GithubHelp logo

Nulls in response about odata-client HOT 12 CLOSED

davidmoten avatar davidmoten commented on June 1, 2024
Nulls in response

from odata-client.

Comments (12)

davidmoten avatar davidmoten commented on June 1, 2024

definitely a defect, introduced by recent fix. I'll have a look, thanks!

from odata-client.

davidmoten avatar davidmoten commented on June 1, 2024

Ah wait, this is not the response from the graph service but what happens when you serialize a User object? How do you serialize it? In a recent fix I did remove an annotation from entity objects so that you will now have to instruct the serializer to exclude nulls. Serializer.INSTANCE does this by default:

User user = User.builderUser().id("12345").build();
System.out.println(Serializer.INSTANCE.serialize(user));

output:

{"@odata.type":"microsoft.graph.user","id":"12345"}

from odata-client.

RajatNair avatar RajatNair commented on June 1, 2024

How do you serialize it?

Serializing it using Spring Webflux -

ServerResponse.ok().contentType(MediaType.APPLICATION_STREAM_JSON).body(this.service.listUsers(), User.class)

where listUsers return Flux<Stream<odata.msgraph.client.entity.User>>

The above sample I had posted using v0.1.12 and v0.1.17 was using the same code.

from odata-client.

davidmoten avatar davidmoten commented on June 1, 2024

Entity objects used to have a class level annotation @JsonInclude(Include.NON_NULL) which was friendly for your use case. I removed that annotation because it was breaking a scenario where we do want to serialize some or all nulls (updating fields to null in a patch).

So if you are serializing it using Spring Webflux then just configure Webflux to exclude nulls. I found lots of information when I googled "webflux customize json serialization"

from odata-client.

davidmoten avatar davidmoten commented on June 1, 2024

I'll have a look at returning the class level annotation but I doubt that I can override it (which I need to do). So no promises!

from odata-client.

davidmoten avatar davidmoten commented on June 1, 2024

Ah yes, I can override the class level annotation. So don't worry about customizing your serializer, I'll change all generated objects to have @JsonInclude(Include.NON_NULL) again.

from odata-client.

davidmoten avatar davidmoten commented on June 1, 2024

Trying to do this I think I've encountered Jackson bugs in relation to setting the AnnotationInspector. I've got a workaround but feels like I've opened a Pandora's box of more detective work!

from odata-client.

davidmoten avatar davidmoten commented on June 1, 2024

The change you want is in release 0.1.20 on Maven Central now.

from odata-client.

davidmoten avatar davidmoten commented on June 1, 2024

By the way we can probably get the default serialization to suppress including empty arrays as well. I'll have to make sure it doesn't have any nasty side-effects though.

from odata-client.

davidmoten avatar davidmoten commented on June 1, 2024

I think this is done so closing. Reopen if you need to.

from odata-client.

RajatNair avatar RajatNair commented on June 1, 2024

I think this is done so closing. Reopen if you need to.

Validated the fix, it's working as expected. Thanks.

By the way we can probably get the default serialization to suppress including empty arrays as well. I'll have to make sure it doesn't have any nasty side-effects though.

Can you give me some pointers? Which Jackson class should I be extending?

from odata-client.

davidmoten avatar davidmoten commented on June 1, 2024

Validated the fix, it's working as expected. Thanks.

Good to hear.

By the way we can probably get the default serialization to suppress including empty arrays as well. I'll have to make sure it doesn't have any nasty side-effects though.

Can you give me some pointers? Which Jackson class should I be extending?

I would just replace the @JsonInclude(Include.NON_NULL) annotation at the top of all entities, complex types, collectionPage with @JsonInclude(Include.NON_EMPTY).

from odata-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.