Add retention policy to annotations

This commit is contained in:
Aria 2023-06-16 01:46:30 -07:00
parent 642044a15a
commit d764e6c7b4
6 changed files with 20 additions and 0 deletions

View file

@ -1,5 +1,8 @@
package dev.zontreck.ariaslib.json;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Serialization or Deserialization has completed.
*
@ -7,5 +10,6 @@ package dev.zontreck.ariaslib.json;
*
* Boolean: True for deserialization.
*/
@Retention ( RetentionPolicy.RUNTIME )
public @interface Completed {
}

View file

@ -1,7 +1,11 @@
package dev.zontreck.ariaslib.json;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Used on a class to indicate that it is serializable by the dynamic serializer.
*/
@Retention ( RetentionPolicy.RUNTIME )
public @interface DynSerial {
}

View file

@ -31,6 +31,9 @@ public class DynamicDeserializer
Field field :
fields
) {
field.setAccessible ( true );
if( !( field.getType ().isAnnotationPresent ( DynSerial.class ) ))
{
field.set ( object, map.get ( field.getName () ) );

View file

@ -45,6 +45,7 @@ public class DynamicSerializer {
Field field :
fields
) {
field.setAccessible ( true );
if ( field.isAnnotationPresent ( IgnoreSerialization.class ) )
continue;
Object fieldVal = field.get ( inst );

View file

@ -1,8 +1,12 @@
package dev.zontreck.ariaslib.json;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Marks an element to be ignored completely by the serializer or deserializer.
*/
@Retention ( RetentionPolicy.RUNTIME )
public @interface IgnoreSerialization
{
}

View file

@ -1,9 +1,13 @@
package dev.zontreck.ariaslib.json;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* To be set on a method, and will invoke that method prior to serialization beginning.
*
* Preparations should be made here
*/
@Retention ( RetentionPolicy.RUNTIME )
public @interface PreSerialize {
}