/// <exception cref="System.Exception"/> public JAXBContextResolver() { JAXBContext context; JAXBContext unWrappedRootContext; // you have to specify all the dao classes here Type[] cTypes = new Type[] { typeof(AppInfo), typeof(AppAttemptInfo), typeof(AppAttemptsInfo ), typeof(ClusterInfo), typeof(CapacitySchedulerQueueInfo), typeof(FifoSchedulerInfo ), typeof(SchedulerTypeInfo), typeof(NodeInfo), typeof(UserMetricsInfo), typeof( CapacitySchedulerInfo), typeof(ClusterMetricsInfo), typeof(SchedulerInfo), typeof( AppsInfo), typeof(NodesInfo), typeof(RemoteExceptionData), typeof(CapacitySchedulerQueueInfoList ), typeof(ResourceInfo), typeof(UsersInfo), typeof(UserInfo), typeof(ApplicationStatisticsInfo ), typeof(StatisticsItemInfo) }; // these dao classes need root unwrapping Type[] rootUnwrappedTypes = new Type[] { typeof(NewApplication), typeof(ApplicationSubmissionContextInfo ), typeof(ContainerLaunchContextInfo), typeof(LocalResourceInfo), typeof(DelegationToken ), typeof(AppQueue) }; this.typesContextMap = new Dictionary <Type, JAXBContext>(); context = new JSONJAXBContext(JSONConfiguration.Natural().RootUnwrapping(false).Build (), cTypes); unWrappedRootContext = new JSONJAXBContext(JSONConfiguration.Natural().RootUnwrapping (true).Build(), rootUnwrappedTypes); foreach (Type type in cTypes) { typesContextMap[type] = context; } foreach (Type type_1 in rootUnwrappedTypes) { typesContextMap[type_1] = unWrappedRootContext; } }
/// <exception cref="System.Exception"/> private object FromJson(string json, Type klass) { StringReader sr = new StringReader(json); JSONJAXBContext ctx = new JSONJAXBContext(klass); JSONUnmarshaller jm = ctx.CreateJSONUnmarshaller(); return(jm.UnmarshalFromJSON(sr, klass)); }
/// <exception cref="System.Exception"/> private string ToJson(object nsli, Type klass) { StringWriter sw = new StringWriter(); JSONJAXBContext ctx = new JSONJAXBContext(klass); JSONMarshaller jm = ctx.CreateJSONMarshaller(); jm.MarshallToJSON(nsli, sw); return(sw.ToString()); }