Skip to content

Commit

Permalink
Extract JsonConverters into new JSON package
Browse files Browse the repository at this point in the history
  • Loading branch information
mvriel committed Jul 17, 2023
1 parent a7da8d8 commit 21fb17c
Show file tree
Hide file tree
Showing 21 changed files with 159 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using Netherlands3D.Indicators.JsonConverters;
using Netherlands3D.Json.JsonConverters;
using Newtonsoft.Json;

namespace Netherlands3D.Indicators.Dossier.DataLayers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using Netherlands3D.Indicators.JsonConverters;
using Netherlands3D.Json.JsonConverters;
using Newtonsoft.Json;
using UnityEngine;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using Netherlands3D.Indicators.JsonConverters;
using Netherlands3D.Json.JsonConverters;
using Newtonsoft.Json;

namespace Netherlands3D.Indicators.Dossier.Indicators
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"rootNamespace": "Netherlands3D.Indicators",
"references": [
"GUID:33a0d05a98c744ae9baf0f37b6cd5e93",
"GUID:6055be8ebefd69e48b49212b09b47b2f"
"GUID:6055be8ebefd69e48b49212b09b47b2f",
"GUID:871b38c5af53a0544a0ecda2e0492310"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
12 changes: 12 additions & 0 deletions Packages/eu.netherlands3d.json/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Changelog
All notable changes to this package will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- JsonConverter for UnityEngine.Color
- JsonConverter for System.URI
7 changes: 7 additions & 0 deletions Packages/eu.netherlands3d.json/CHANGELOG.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions Packages/eu.netherlands3d.json/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# JSON Extra's for Netherlands3D

## Installing

This package is provided through OpenUPM, to install it using the CLI you can perform the following:

```bash
$ openupm add eu.netherlands3d.json
```

or, you have to add `https://package.openupm.com` as a scoped registry with, at least, the following scopes:

- `eu.netherlands3d`

## JSON Converters

## Color

A JSON Converter for JSON.net is provided that can interpret hexadecimal or CSS-named color codes in JSON, and convert
them into UnityEngine.Color objects. To use this, ensure the type of a field is UnityEngine.Color and add the following
annotation:

```csharp
using UnityEngine;
using Netherlands3D.Json.JsonConverters;
using Newtonsoft.Json;

class MyJson {
[JsonConverter(typeof(ColorConverter))]
public Color $color;
}
```

Accepted color variants are every variant supported by [ColorUtility.TryParseHtmlString](https://docs.unity3d.com/ScriptReference/ColorUtility.TryParseHtmlString.html).
When serializing to a JSON file, it will always output as `#RRGGBBAA`.

## System.URI

A JSON Converter for JSON.net is provided that can interpret URIs in JSON and convert them into URI objects. To use
this, ensure the type of a field is System.URI and add the following annotation:

```csharp
using System;
using Netherlands3D.Json.JsonConverters;
using Newtonsoft.Json;

class MyJson {
[JsonConverter(typeof(UriConverter))]
public Uri $uri;
}
```
3 changes: 3 additions & 0 deletions Packages/eu.netherlands3d.json/README.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Packages/eu.netherlands3d.json/Runtime.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Packages/eu.netherlands3d.json/Runtime/Scripts.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Newtonsoft.Json;
using UnityEngine;

namespace Netherlands3D.Indicators.JsonConverters
namespace Netherlands3D.Json.JsonConverters
{
public class ColorConverter : JsonConverter<Color>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using Newtonsoft.Json;
using UnityEngine;

namespace Netherlands3D.Indicators.JsonConverters
namespace Netherlands3D.Json.JsonConverters
{
public class UriConverter : JsonConverter<Uri>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "eu.netherlands3d.json.Runtime",
"rootNamespace": "Netherlands3D.Json",
"references": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions Packages/eu.netherlands3d.json/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "eu.netherlands3d.json",
"version": "1.0.0",
"displayName": "Netherlands3D - JSON Extras",
"description": "A series of extras for working with JSON in the context of Netherlands3D",
"unity": "2022.2",
"documentationUrl": "https://netherlands3d.eu/docs",
"changelogUrl": "https://example.com/changelog.html",
"licensesUrl": "https://example.com/licensing.html",
"keywords": [
"digital-twin",
"json.net",
"newtonsoft",
"json"
],
"author": {
"name": "Netherlands3D",
"url": "https://www.netherlands3d.eu"
},
"dependencies": {
"com.unity.nuget.newtonsoft-json": "3.2.0"
}
}
3 changes: 3 additions & 0 deletions Packages/eu.netherlands3d.json/package.json.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@
"com.virgis.geojson.net": "1.2.17"
}
},
"eu.netherlands3d.json": {
"version": "file:eu.netherlands3d.json",
"depth": 0,
"source": "embedded",
"dependencies": {
"com.unity.nuget.newtonsoft-json": "3.2.0"
}
},
"eu.netherlands3d.tilehandler-styling": {
"version": "file:eu.netherlands3d.tilehandler-styling",
"depth": 0,
Expand Down

0 comments on commit 21fb17c

Please sign in to comment.