1 module painlessjson.annotations; 2 3 import painlessjson..string; 4 import painlesstraits; 5 6 struct SerializedToName 7 { 8 string name; 9 } 10 11 struct SerializedFromName 12 { 13 string name; 14 } 15 16 struct SerializedName 17 { 18 string to; 19 string from; 20 this(string serializedName) 21 { 22 to = from = serializedName; 23 } 24 25 this(string to, string from) 26 { 27 this.to = to; 28 this.from = from; 29 } 30 31 } 32 33 struct SerializeIgnore 34 { 35 } 36 37 struct SerializeToIgnore 38 { 39 } 40 41 struct SerializeFromIgnore 42 { 43 } 44 45 template serializationToName(alias T, string defaultName, bool alsoAcceptUnderscore) 46 { 47 static string helper() 48 { 49 static if (hasValueAnnotation!(T, SerializedName) && getAnnotation!(T, SerializedName).to) 50 { 51 return getAnnotation!(T, SerializedName).to; 52 } 53 else static if (hasValueAnnotation!(T, SerializedToName) 54 && getAnnotation!(T, SerializedToName).name) 55 { 56 return getAnnotation!(T, SerializedToName).name; 57 } else static if(alsoAcceptUnderscore) 58 { 59 return camelCaseToUnderscore(defaultName); 60 } 61 else 62 { 63 return defaultName; 64 } 65 } 66 67 enum string serializationToName = helper; 68 } 69 70 template serializationFromName(alias T, string defaultName) 71 { 72 static string helper() 73 { 74 static if (hasValueAnnotation!(T, SerializedName) && getAnnotation!(T, 75 SerializedName).from) 76 { 77 return getAnnotation!(T, SerializedName).from; 78 } 79 else static if (hasValueAnnotation!(T, SerializedFromName) 80 && getAnnotation!(T, SerializedFromName).name) 81 { 82 return getAnnotation!(T, SerializedFromName).name; 83 } 84 else 85 { 86 return defaultName; 87 } 88 } 89 90 enum string serializationFromName = helper; 91 }