Giter Club home page Giter Club logo

Comments (6)

gmurt avatar gmurt commented on June 15, 2024 2

Hi Andrea,

I think there may be a bug with the MARS.JsonDataObjects.ReadersAndWriters where it doesn't use a "fallback" encoding.

I've modified the source to resemble the standard JSON fallback mechanism as in the "procedure TJSONValueWriter.WriteTo" method.

My changed code looks like this and now appears to work without giving an Access Violation. Can you check if this was a bug and if this is a suitable fix?

procedure TJsonDataObjectsWriter.WriteTo(const AValue: TValue; const AMediaType: TMediaType;
  AOutputStream: TStream; const AActivation: IMARSActivation);
var
  LJsonBO: TJsonBaseObject;
  LEncoding: TEncoding;
begin
  if not GetDesiredEncoding(AActivation, LEncoding) then
    LEncoding := TEncoding.UTF8; // UTF8 by default

from mars.

andrea-magni avatar andrea-magni commented on June 15, 2024

Hi @gmurt, thanks for opening this issue.
The problem arise because since latest changes to the MessageBodyWriter mechanism, MARS do not have a fallback mechanism anymore. It will try to lookup for a MBW for one of the media types specified by the client through the Accept header and, if none matches, it raises that exception.
If you do the same request (let's say with PostMan) specifying the Accept header's value to 'application/json', everything should run smoothly. The browser (Chrome) usually send an Accept header like this: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8' and, as you can see, application/json is not listed. However the wildcard (/) is actually listed so I agree it is a bug that MARS do not properly match the wildcard against the media types each MBW states to support (through the Produces custom attribute of its definition).
I have improved (hopefully fixed) this in the develop branch and now it seems to me the general behavior of the library with respect to wildcard and quality factor specification is much better.
Please check the develop branch and if everything seems fine to you also, we can close this issue.

BTW I also noticed there was a compilation error with the Demos/JsonDataObjects project (here: b49d3b3#diff-d035c020eaab32e2aa473242ca144e82L56 ) and I fixed it also.

Thanks

from mars.

gmurt avatar gmurt commented on June 15, 2024

Thanks Andrea and sorry for the delay.

I will test again today and let you know how it goes.

from mars.

andrea-magni avatar andrea-magni commented on June 15, 2024

Any news about this issue, @gmurt ?

Thanks

from mars.

gmurt avatar gmurt commented on June 15, 2024

from mars.

andrea-magni avatar andrea-magni commented on June 15, 2024

Don't worry @gmurt and happy skiing ;-)
Best regards, Andrea

from mars.

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.