Refactor Api-Client
Add Exceptionhandler, AlertService JSON-Converter AppSettings via DI Reformat Code
This commit is contained in:
@@ -11,37 +11,44 @@ namespace Jugenddienst_Stunden.Models {
|
||||
return typeof(T).IsAssignableFrom(objectType);
|
||||
}
|
||||
|
||||
public override bool CanWrite { get { return false; } }
|
||||
public override bool CanWrite {
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
|
||||
JsonSerializer serializer) {
|
||||
var contract = serializer.ContractResolver.ResolveContract(objectType);
|
||||
if (!(contract is Newtonsoft.Json.Serialization.JsonObjectContract || contract is Newtonsoft.Json.Serialization.JsonDictionaryContract)) {
|
||||
throw new JsonSerializationException(string.Format("Unsupported objectType {0} at {1}.", objectType, reader.Path));
|
||||
if (!(contract is Newtonsoft.Json.Serialization.JsonObjectContract ||
|
||||
contract is Newtonsoft.Json.Serialization.JsonDictionaryContract)) {
|
||||
throw new JsonSerializationException(string.Format("Unsupported objectType {0} at {1}.", objectType,
|
||||
reader.Path));
|
||||
}
|
||||
|
||||
switch (reader.SkipComments().TokenType) {
|
||||
case JsonToken.StartArray: {
|
||||
int count = 0;
|
||||
while (reader.Read()) {
|
||||
switch (reader.TokenType) {
|
||||
case JsonToken.Comment:
|
||||
break;
|
||||
case JsonToken.EndArray:
|
||||
return existingValue;
|
||||
default: {
|
||||
count++;
|
||||
if (count > 1)
|
||||
throw new JsonSerializationException(string.Format("Too many objects at path {0}.", reader.Path));
|
||||
existingValue = existingValue ?? contract.DefaultCreator();
|
||||
serializer.Populate(reader, existingValue);
|
||||
}
|
||||
break;
|
||||
int count = 0;
|
||||
while (reader.Read()) {
|
||||
switch (reader.TokenType) {
|
||||
case JsonToken.Comment:
|
||||
break;
|
||||
case JsonToken.EndArray:
|
||||
return existingValue;
|
||||
default: {
|
||||
count++;
|
||||
if (count > 1)
|
||||
throw new JsonSerializationException(string.Format("Too many objects at path {0}.",
|
||||
reader.Path));
|
||||
existingValue = existingValue ?? contract.DefaultCreator();
|
||||
serializer.Populate(reader, existingValue);
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Should not come here.
|
||||
throw new JsonSerializationException(string.Format("Unclosed array at path {0}.", reader.Path));
|
||||
}
|
||||
|
||||
// Should not come here.
|
||||
throw new JsonSerializationException(string.Format("Unclosed array at path {0}.", reader.Path));
|
||||
}
|
||||
|
||||
case JsonToken.Null:
|
||||
return null;
|
||||
|
||||
@@ -67,4 +74,4 @@ namespace Jugenddienst_Stunden.Models {
|
||||
return reader;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user