Comments (3)
This seems related: #2839
from newtonsoft.json.
I've narrowed it down to line 2204 in JsonTextReader.cs
, where it inspects _floatParseHandling
. Wouldn't a fallback mechanism here work?
e.g. attempting conversion to decimal
, and if it overflows go to double
instead of throwing?
I realize it should probably have a new FloatParseHandling
enum value to avoid breaking existing implementations. Something like DecimalWithFallbackToDouble
(or something more concise)
Just an idea.
from newtonsoft.json.
Typy źródłowe/docelowe
internal record Example(double Double, decimal Decimal);Źródłowy/docelowy kod JSON
{"Double":-1.7976931348623157E+308,"Decimal":-79228162514264337593543950335.0}Oczekiwane zachowanie
Oczekuję, że będzie można deserializować kod JSON z powrotem do przykładowego rekordu, nawet w przypadku korzystania z tego niestandardowego:
JsonConverter
class CustomConverter : JsonConverter { public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) { // Not relevant } public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) { var token = JToken.ReadFrom(reader); var dbl = double.Parse(token["Double"]!.ToString()); var dec = decimal.Parse(token["Decimal"]!.ToString()); // Throws FormatException return new Example(dbl, dec); } public override bool CanConvert(Type objectType) => true; }
Rzeczywiste zachowanie
A jest zgłaszany podczas próby przeanalizowania ułamka dziesiętnego, ponieważ czytelnik domyślnie traktuje wszystkie liczby zmiennoprzecinkowe tak samo za pośrednictwem właściwości. Zmiana właściwości na po prostu przenosi problem do analizowania zamiast tego.
FormatException``FloatParseHandling``FloatParseHandling``Decimal``double
Steps to reproduce
var example = new Example(double.MinValue, decimal.MinValue); var json = JsonConvert.SerializeObject(example); var deserialized = JsonConvert.DeserializeObject<Example>(json, new CustomConverter());
from newtonsoft.json.
Related Issues (20)
- Support for JsonSerializer.Context when StreamingContext is removed HOT 3
- Deserializing with `NullValueHandling.Ignore` for a type with constructor parameters doesn't ignore null values HOT 2
- Json.NET deserializes nested types using only the last entry in the nested array HOT 2
- error CS0104: 'Func<,>' is an ambiguous reference between 'Newtonsoft.Json.Serialization.Func<T, TResult>' and 'System.Func<T, TResult>' HOT 5
- Exception during deserialization with TypeNameHandling = TypeNameHandling.All a json that was saved by browser HOT 2
- Could not determine JSON object type for type System.Collections.Generic.KeyValuePair HOT 1
- Unity cyclic references of Unity objects HOT 2
- NullReferenceException in JsonSerializer.GetMatchingConverter(IList<JsonConverter> converters, Type objectType) HOT 7
- Ignoring JsonProperty Name HOT 2
- [Enhancement] when serializing/deserializing a netstandard lib used in .net framework/ net core
- JsonConvert.DeserializeObject appends value for no reason HOT 2
- Ask for the "PrivacyInfo.xcprivacy" required by Apple
- [Bug] CreateProperties adds JsonIgnore fields when it should not MemberSerialization.OptOut HOT 2
- Could not create an instance of type X. Type is an interface or abstract class and cannot be instantiated. HOT 2
- Problem with Deserialize number like 0...8 and 0...9 HOT 2
- deserialize object Ignore case HOT 1
- Deserializing object of missing class as it's Base class (C#) HOT 1
- Source code version problem HOT 1
- [Feature Request] MissingMemberHandling attribute HOT 4
- JsonConvert.DeserializeObject using $type does not (at least for the root object) not use the converter HOT 3
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 newtonsoft.json.