Comments (6)
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.
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.
Thanks Andrea and sorry for the delay.
I will test again today and let you know how it goes.
from mars.
Any news about this issue, @gmurt ?
Thanks
from mars.
from mars.
Don't worry @gmurt and happy skiing ;-)
Best regards, Andrea
from mars.
Related Issues (20)
- Understanding "DefaultMARSJSONSerializationOptions.DateIsUTC" HOT 3
- Rate limiter HOT 1
- Issue with TObject and TArray<TObject> deserialization
- GET method to upload a file HOT 2
- Memory leak in TJSONObjectHelper.WriteStringValue HOT 1
- OpenAPI 3 schema serialization: property serialization order HOT 1
- Installation fails HOT 3
- OpenApi 3: no bodyparams exported HOT 1
- OpenAPI 3 broken if " DefaultMARSJSONSerializationOptions.SkipEmptyValues := False; "
- on Linux64: TJSONObjectHelper.ReadBoolValue can't get right value
- Multiple problems on Linux platform.
- Special use case of NULL field value HOT 2
- If CORS is enabled, the Access-Control-Allow-Methods are missing the PATCH method
- ThreadPoolSize HOT 1
- MARS change the request url if it finish with a slash
- [DCC Fatal Error] Net.CrossSocket.pas(21): F2613 Unit 'Net.CrossSocket.Epoll' not found. HOT 1
- Compilation fail if you use MARS.Utils.ReqRespLogger.Memory HOT 1
- Error compile in Delphi 12 HOT 1
- Memory Leak found HOT 2
- New resource for document API in StopLight format
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mars.