forked from ln-dotnet/ln.json
26 lines
649 B
C#
26 lines
649 B
C#
using System;
|
|
|
|
namespace ln.json.mapping
|
|
{
|
|
public class JSONByteArrayMapping : JSONMapping
|
|
{
|
|
public JSONByteArrayMapping()
|
|
: base(typeof(byte[]))
|
|
{
|
|
}
|
|
|
|
public override object FromJson(JSONMapper mapper, JSONValue json)
|
|
{
|
|
if (json is JSONString jString)
|
|
{
|
|
return Convert.FromBase64String(jString.Value);
|
|
}
|
|
throw new NotSupportedException();
|
|
}
|
|
|
|
public override JSONValue ToJson(JSONMapper mapper, object value)
|
|
{
|
|
return new JSONString(Convert.ToBase64String((byte[])value));
|
|
}
|
|
}
|
|
} |