Skip to content

Commit

Permalink
Refine
Browse files Browse the repository at this point in the history
  • Loading branch information
ksprider committed Apr 1, 2021
1 parent 4d7f113 commit 5acd862
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 26 deletions.
73 changes: 71 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,33 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.kspider</groupId>
<groupId>com.github.ksprider</groupId>
<artifactId>Surgical</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>Surgical</name>
<version>0.0.1</version>
<description>A tool for dynamically filtering entity properties based on Jackson</description>
<url>https://github.com/ksprider/Surgical</url>

<developers>
<developer>
<name>King</name>
<email>King@kspider.xyz</email>
<url>https://github.com/ksprider</url>
</developer>
</developers>

<licenses>
<license>
<name>MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
<distribution>repo</distribution>
</license>
</licenses>

<scm>
<url>https://github.com/ksprider/Surgical</url>
</scm>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -36,6 +59,17 @@
</dependency>
</dependencies>

<distributionManagement>
<snapshotRepository>
<id>oss</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>oss</id>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<plugins>
Expand All @@ -52,6 +86,41 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
package com.github.kspider.surgical;
package com.github.ksprider.surgical;

import com.fasterxml.jackson.databind.ser.BeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.FilterProvider;
import com.fasterxml.jackson.databind.ser.PropertyFilter;

public class CustomFilterProvider<T> extends FilterProvider {

private final T root;
private final SerializationHandler<T> serializerHandler;
private final String location;
private final CustomPropertyFilter customPropertyFilter;

public CustomFilterProvider(T root, SerializationHandler<T> serializerHandler, String location) {
this.root = root;
this.serializerHandler = serializerHandler;
this.location = location;
this.customPropertyFilter = new CustomPropertyFilter<>(root, serializerHandler, location);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.kspider.surgical;
package com.github.ksprider.surgical;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonStreamContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.kspider.surgical;
package com.github.ksprider.surgical;

import com.fasterxml.jackson.core.JsonStreamContext;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.kspider.surgical;
package com.github.ksprider.surgical;

public interface TreeHandler<T> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.kspider.surgical.node;
package com.github.ksprider.surgical.node;

import java.util.HashMap;
import java.util.HashSet;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.kspider.surgical.node;
package com.github.ksprider.surgical.node;

import com.fasterxml.jackson.core.JsonStreamContext;
import com.github.kspider.surgical.SerializationHandler;
import com.github.ksprider.surgical.SerializationHandler;
import org.springframework.stereotype.Service;

import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.kspider.surgical.node;
package com.github.ksprider.surgical.node;

import com.github.kspider.surgical.TreeHandler;
import com.github.ksprider.surgical.TreeHandler;
import org.springframework.stereotype.Service;

import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.kspider.surgical.spring.mvc;
package com.github.ksprider.surgical.spring.mvc;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.github.kspider.surgical.spring.mvc;
package com.github.ksprider.surgical.spring.mvc;

import com.github.kspider.surgical.CustomFilterProvider;
import com.github.kspider.surgical.SerializationHandler;
import com.github.kspider.surgical.TreeHandler;
import com.github.kspider.surgical.node.Node;
import com.github.ksprider.surgical.CustomFilterProvider;
import com.github.ksprider.surgical.SerializationHandler;
import com.github.ksprider.surgical.TreeHandler;
import com.github.ksprider.surgical.node.Node;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
Expand All @@ -23,7 +23,7 @@ public class JSONResponseBodyAdvice implements ResponseBodyAdvice<Object> {

private TreeHandler<Node> treeHandler;
private SerializationHandler<Node> serializationHandler;
private Map<String, CustomFilterProvider> cache = new HashMap<>();
private final Map<String, CustomFilterProvider> cache = new HashMap<>();

@Autowired
public void setTreeHandler(TreeHandler<Node> treeHandler) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.github.kspider.surgical.spring.mvc;
package com.github.ksprider.surgical.spring.mvc;

import com.fasterxml.jackson.annotation.JsonFilter;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import java.io.Serializable;

@Configuration
public class ObjectMapperConfig implements InitializingBean {

Expand All @@ -18,7 +20,7 @@ public void setObjectMapper(ObjectMapper objectMapper) {

@Override
public void afterPropertiesSet() throws Exception {
objectMapper.addMixIn(Object.class, CustomPropertyFilterMixIn.class);
objectMapper.addMixIn(Serializable.class, CustomPropertyFilterMixIn.class);
}

@JsonFilter("customPropertyFilter")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.github.ksprider.surgical.spring.mvc.config;

import org.springframework.context.annotation.Import;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Import(JSONConfiguration.class)
public @interface EnableJSON {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.github.ksprider.surgical.spring.mvc.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan("com.github.ksprider.surgical")
public class JSONConfiguration {
}

0 comments on commit 5acd862

Please sign in to comment.