Search Feedback

223
votes

Add support for Nullable Types to JsonUtility

Scripting

-

-

Unity’s JsonUtility (docs.unity3d.com/ScriptReference/JsonUtility) doesn’t support the additional null value of the serialized Nullable Types (docs.microsoft.com/en-us/dotnet/csharp/programming-guide/nullable-types).

The ability to assign null to numeric and Boolean types is especially useful when dealing with databases and other data types that contain elements that may not be assigned a value. For example, a Boolean field in a database can store the values true or false, or it may be undefined.

Comments (3)

  1. 6ca9b47a9d0092f513d714d2f5b9b8f6?d=mm

    MarkHenryC

    Jan 30, 2019 01:37

    Not looking so popular, but I'd vouch for nullable support. When you don't need a heavyweight json manager, the Unity utility is good, but for config files, nullable is very useful. For example, you may have an internal float value that you can override via a config json file. But if that field isn't in the json data you probably don't want the value to default to zero. Checking for HasValue is really useful here.

  2. 019564238c4171803b57962033932d21?d=mm

    VadimPyrozhok

    Sep 24, 2018 08:47

    I have to admit this is a problem. It would be much easier to have normally serialized fields like "TeamNumber": null , instead of having "TeamNumber": ""
    So we as developers wouldn't have to come up with some strange tricky solutions for sending normal POST requests.

  3. 6a51bb25c72b938fed68ec22d75ab43c?d=mm

    earthcrosser

    Sep 04, 2018 13:50

    It would be great if you could leave out values from the JSON string as well. Like if you have a value that is null, it gets skipped and doesn't show up in the JSON string that is created.

Your opinion counts

Help us make things better. Share your great idea for improving Unity or vote for other people’s.

Log in to post a new idea

Categories

All

(11034)

2D

(291)

Ads

(63)

AI & Navigation

(83)

Analytics

(130)

Animation

(413)

Asset Store

(371)

Asset Store Publisher

(21)

Assets

(557)

Audio

(185)

Cloud Build

(154)

Collaborate

(70)

Docs & Tutorials

(251)

Editor

(2579)

Everyplay

(17)

Game Performance Reporting

(22)

General

(1003)

Graphics

(903)

GUI

(447)

Input

(173)

Licensing

(93)

Networking

(193)

Physics

(392)

Platforms

(448)

Profiling & Optimization

(84)

Runtime

(188)

Scripting

(1154)

Terrain

(178)

WebGL

(145)