Package Torello.Java.JSON
Class BaseType
- java.lang.Object
-
- Torello.Java.JSON.BaseType
-
- Direct Known Subclasses:
Accessibility.AXNode
,Accessibility.AXProperty
,Accessibility.AXRelatedNode
,Accessibility.AXValue
,Accessibility.AXValueSource
,Animation._Animation
,Animation.AnimationEffect
,Animation.KeyframesRule
,Animation.KeyframeStyle
,Audits.AffectedCookie
,Audits.AffectedFrame
,Audits.AffectedRequest
,Audits.AttributionReportingIssueDetails
,Audits.BlockedByResponseIssueDetails
,Audits.ContentSecurityPolicyIssueDetails
,Audits.CorsIssueDetails
,Audits.GenericIssueDetails
,Audits.HeavyAdIssueDetails
,Audits.InspectorIssue
,Audits.InspectorIssueDetails
,Audits.LowTextContrastIssueDetails
,Audits.MixedContentIssueDetails
,Audits.NavigatorUserAgentIssueDetails
,Audits.QuirksModeIssueDetails
,Audits.SameSiteCookieIssueDetails
,Audits.SharedArrayBufferIssueDetails
,Audits.SourceCodeLocation
,Audits.TrustedWebActivityIssueDetails
,Audits.WasmCrossOriginModuleSharingIssueDetails
,BackgroundService.BackgroundServiceEvent
,BackgroundService.EventMetadata
,Browser.Bounds
,Browser.Bucket
,Browser.Histogram
,Browser.PermissionDescriptor
,BrowserEvent
,CacheStorage.Cache
,CacheStorage.CachedResponse
,CacheStorage.DataEntry
,CacheStorage.Header
,Cast.Sink
,Console.ConsoleMessage
,CSS.CSSComputedStyleProperty
,CSS.CSSContainerQuery
,CSS.CSSKeyframeRule
,CSS.CSSKeyframesRule
,CSS.CSSMedia
,CSS.CSSProperty
,CSS.CSSRule
,CSS.CSSStyle
,CSS.CSSStyleSheetHeader
,CSS.FontFace
,CSS.FontVariationAxis
,CSS.InheritedStyleEntry
,CSS.MediaQuery
,CSS.MediaQueryExpression
,CSS.PlatformFontUsage
,CSS.PseudoElementMatches
,CSS.RuleMatch
,CSS.RuleUsage
,CSS.SelectorList
,CSS.ShorthandEntry
,CSS.SourceRange
,CSS.StyleDeclarationEdit
,CSS.Value
,Database._Database
,Database.Error
,Debugger.BreakLocation
,Debugger.CallFrame
,Debugger.DebugSymbols
,Debugger.Location
,Debugger.LocationRange
,Debugger.Scope
,Debugger.ScriptPosition
,Debugger.SearchMatch
,DOM.BackendNode
,DOM.BoxModel
,DOM.CSSComputedStyleProperty
,DOM.Node
,DOM.Rect
,DOM.RGBA
,DOM.ShapeOutsideInfo
,DOMDebugger.EventListener
,DOMSnapshot.ComputedStyle
,DOMSnapshot.DocumentSnapshot
,DOMSnapshot.DOMNode
,DOMSnapshot.InlineTextBox
,DOMSnapshot.LayoutTreeNode
,DOMSnapshot.LayoutTreeSnapshot
,DOMSnapshot.NameValue
,DOMSnapshot.NodeTreeSnapshot
,DOMSnapshot.RareBooleanData
,DOMSnapshot.RareIntegerData
,DOMSnapshot.RareStringData
,DOMSnapshot.TextBoxSnapshot
,DOMStorage.StorageId
,Emulation.DisplayFeature
,Emulation.MediaFeature
,Emulation.ScreenOrientation
,Emulation.UserAgentBrandVersion
,Emulation.UserAgentMetadata
,Fetch.AuthChallenge
,Fetch.AuthChallengeResponse
,Fetch.HeaderEntry
,Fetch.RequestPattern
,HeadlessExperimental.ScreenshotParams
,HeapProfiler.SamplingHeapProfile
,HeapProfiler.SamplingHeapProfileNode
,HeapProfiler.SamplingHeapProfileSample
,IndexedDB.DatabaseWithObjectStores
,IndexedDB.DataEntry
,IndexedDB.Key
,IndexedDB.KeyPath
,IndexedDB.KeyRange
,IndexedDB.ObjectStore
,IndexedDB.ObjectStoreIndex
,Input.DragData
,Input.DragDataItem
,Input.TouchPoint
,LayerTree.Layer
,LayerTree.PictureTile
,LayerTree.ScrollRect
,LayerTree.StickyPositionConstraint
,Log.LogEntry
,Log.ViolationSetting
,Media.PlayerError
,Media.PlayerEvent
,Media.PlayerMessage
,Media.PlayerProperty
,Memory.Module
,Memory.SamplingProfile
,Memory.SamplingProfileNode
,Network.AuthChallenge
,Network.AuthChallengeResponse
,Network.BlockedCookieWithReason
,Network.BlockedSetCookieWithReason
,Network.CachedResource
,Network.ClientSecurityState
,Network.ConnectTiming
,Network.Cookie
,Network.CookieParam
,Network.CorsErrorStatus
,Network.CrossOriginEmbedderPolicyStatus
,Network.CrossOriginOpenerPolicyStatus
,Network.Initiator
,Network.LoadNetworkResourceOptions
,Network.LoadNetworkResourcePageResult
,Network.PostDataEntry
,Network.ReportingApiReport
,Network.Request
,Network.RequestPattern
,Network.ResourceTiming
,Network.Response
,Network.SecurityDetails
,Network.SecurityIsolationStatus
,Network.SignedCertificateTimestamp
,Network.SignedExchangeError
,Network.SignedExchangeHeader
,Network.SignedExchangeInfo
,Network.SignedExchangeSignature
,Network.TrustTokenParams
,Network.WebSocketFrame
,Network.WebSocketRequest
,Network.WebSocketResponse
,Overlay.BoxStyle
,Overlay.ContainerQueryContainerHighlightConfig
,Overlay.ContainerQueryHighlightConfig
,Overlay.FlexContainerHighlightConfig
,Overlay.FlexItemHighlightConfig
,Overlay.FlexNodeHighlightConfig
,Overlay.GridHighlightConfig
,Overlay.GridNodeHighlightConfig
,Overlay.HighlightConfig
,Overlay.HingeConfig
,Overlay.IsolatedElementHighlightConfig
,Overlay.IsolationModeHighlightConfig
,Overlay.LineStyle
,Overlay.ScrollSnapContainerHighlightConfig
,Overlay.ScrollSnapHighlightConfig
,Overlay.SourceOrderConfig
,Page.AdFrameStatus
,Page.AppManifestError
,Page.AppManifestParsedProperties
,Page.BackForwardCacheNotRestoredExplanation
,Page.CompilationCacheParams
,Page.FontFamilies
,Page.FontSizes
,Page.Frame
,Page.FrameResource
,Page.FrameResourceTree
,Page.FrameTree
,Page.InstallabilityError
,Page.InstallabilityErrorArgument
,Page.LayoutViewport
,Page.NavigationEntry
,Page.OriginTrial
,Page.OriginTrialToken
,Page.OriginTrialTokenWithStatus
,Page.PermissionsPolicyBlockLocator
,Page.PermissionsPolicyFeatureState
,Page.ScreencastFrameMetadata
,Page.Viewport
,Page.VisualViewport
,Performance.Metric
,PerformanceTimeline.LargestContentfulPaint
,PerformanceTimeline.LayoutShift
,PerformanceTimeline.LayoutShiftAttribution
,PerformanceTimeline.TimelineEvent
,Profiler.CoverageRange
,Profiler.FunctionCoverage
,Profiler.PositionTickInfo
,Profiler.Profile
,Profiler.ProfileNode
,Profiler.ScriptCoverage
,Profiler.ScriptTypeProfile
,Profiler.TypeObject
,Profiler.TypeProfileEntry
,RunTime.CallArgument
,RunTime.CallFrame
,RunTime.CustomPreview
,RunTime.EntryPreview
,RunTime.ExceptionDetails
,RunTime.ExecutionContextDescription
,RunTime.InternalPropertyDescriptor
,RunTime.ObjectPreview
,RunTime.PrivatePropertyDescriptor
,RunTime.PropertyDescriptor
,RunTime.PropertyPreview
,RunTime.RemoteObject
,RunTime.StackTrace
,RunTime.StackTraceId
,Schema.Domain
,Security.CertificateSecurityState
,Security.InsecureContentStatus
,Security.SafetyTipInfo
,Security.SecurityStateExplanation
,Security.VisibleSecurityState
,ServiceWorker.ServiceWorkerErrorMessage
,ServiceWorker.ServiceWorkerRegistration
,ServiceWorker.ServiceWorkerVersion
,Storage.TrustTokens
,Storage.UsageForType
,SystemInfo.GPUDevice
,SystemInfo.GPUInfo
,SystemInfo.ImageDecodeAcceleratorCapability
,SystemInfo.ProcessInfo
,SystemInfo.Size
,SystemInfo.VideoDecodeAcceleratorCapability
,SystemInfo.VideoEncodeAcceleratorCapability
,Target.RemoteLocation
,Target.TargetInfo
,Tracing.TraceConfig
,WebAudio.AudioListener
,WebAudio.AudioNode
,WebAudio.AudioParam
,WebAudio.BaseAudioContext
,WebAudio.ContextRealtimeData
,WebAuthn.Credential
,WebAuthn.VirtualAuthenticatorOptions
public abstract class BaseType extends java.lang.Object
Serializing Java to JSON:
Converting Java-Data (both Java-Primitive's & Reference-Object's) intoJava-Script Object Notation
has one major & extremely-simplifying factor: the Error-Checking stuff is virtually eliminated from your code!
Although reading JSON into Java means worrying about data that may have come from as far away as Timbuktu, converting Java-Data into JSON is literally just reading memory from your own computer's internal heap, and changing that into Stringified JSON Data. Though this certainly is not guaranteed to be an error-free process, it does have the distinct advantage of your knowing there is really no way to tell if you have made an error, or caused an exception, without something or someone from very far away literally calling you on the telephone to tell you that your recent API change has made their code throw exceptions!
As such, the code for this class is extremely simple, and offers virtually no exception hierarchy or error-checking at all. It is tremendously shorter than the other JSON-Binding & Read-JSON classes.This class may be used to help serialize Java Objects into Json Objects.
Currently, the primary use of this class is to serialize any Object-Data that is generated by user-request into a JSON-Object Request. This class is then sent to Chrome, or any RDP-Enabled Browser, so that user-requests may be processed.
Hi-Lited Source-Code:- View Here: Torello/Java/JSON/BaseType.java
- Open New Browser-Tab: Torello/Java/JSON/BaseType.java
File Size: 15,668 Bytes Line Count: 366 '\n' Characters Found
-
-
Constructor Summary
Constructors Modifier Constructor protected
BaseType()
-
Method Summary
Convert to java.lang.String Modifier and Type Method String
toString()
Serialize 'this' to JSON String Modifier and Type Method void
toJSON(String name, JsonGenerator jGen)
Identify which JSON Properties may be absent or null Modifier and Type Method abstract boolean[]
optionals()
-
-
-
Constructor Detail
-
BaseType
protected BaseType()
Do Nothing Constructor
-
-
Method Detail
-
optionals
public abstract boolean[] optionals()
Implementing this method allows sub-classes to specify which JSON Properties may be absent or null. When binding aJsonObject
to a Java-Object, if some of the expected fields for the Java-Object map to Properties which might be left-out or omitted, then that may be indicated by setting that fields array positionTRUE
.
NOTE: This array should have a length equal to the number of fields contained by the Java Object. The first boolean in the array should specify whether the first Object Field may by absent. The second boolean should specify whether the second Object Field is optional in the JSON - and so on and so forth...- Returns:
- A
boolean[]
array whose length is precisely equal to the number of fields in the Java Object.
-
toString
public java.lang.String toString()
This method uses Java Reflection to convert the inheriting object into aString
.- Overrides:
toString
in classjava.lang.Object
- Returns:
- A
java.lang.String
representation of'this'
object. - Code:
- Exact Method Body:
return toString(0);
-
toJSON
public void toJSON(java.lang.String name, JsonGenerator jGen)
Serializes'this'
object into JSON.- It is OK if 'name' is null.
- It is NOT-OK if 'jGen' is null.
- Parameters:
name
- The name being assigned to thisJsonObject
Property. This name may be null. If null is passed here, theJsonGenerator
will treat this Object as the top level JSON Object, not a property of a larger object.jGen
- This is the generator instance. Note that often, when serializing Java Objects to JSON (and vice-versa!), one object may be a property or field of another object. When serializing an object to JSON, if there is a field that also needs to be serialized as aJsonObject
, just pass the name and this generator instance in order to include that field as a sub-property.- Code:
- Exact Method Body:
boolean[] optArr = optionals(); Field[] fArr = this.getClass().getFields(); Vector<Class<?>> cVec = new Vector<>(); Vector<String> nVec = new Vector<>(); Vector<Object> oVec = new Vector<>(); if (fArr.length == 0) throw new JsonException( "Likely, this is an error, but not necessarily. You are attempting to serialize a " + "class that has 0 public fields, into JSON" ); // Retrieve all of the Fields Available to this class. // These Fields should all be public and final try { for (Field f : fArr) if (! Modifier.isStatic(f.getModifiers())) { cVec.add(f.getType()); nVec.add(f.getName()); oVec.add(f.get(this)); } } catch (IllegalAccessException e) { System.out.println("Unable to Access the Field."); System.err.println(EXCC.toString(e)); throw new UnreachableError(); } // Write the value of these fields to the Json-Generator. If no 'name' was provided, // then write the "Top-Level Json-Object" if (name == null) jGen.writeStartObject(); else jGen.writeStartObject(name); WriteJSON.get(jGen, cVec, nVec, oVec, optArr); // Close the writing of 'this' object. jGen.writeEnd();
-
-