kandi background

fastjson | A fast JSON parser/generator for Java. | JSON Processing library

Download this library from

kandi X-RAY | fastjson Summary

fastjson is a Java library typically used in Utilities, JSON Processing applications. fastjson has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has high support. You can download it from GitHub, Maven.
[![Java CI](https://github.com/alibaba/fastjson/actions/workflows/ci.yaml/badge.svg?branch=master)](https://github.com/alibaba/fastjson/actions/workflows/ci.yaml) [![Codecov](https://codecov.io/gh/alibaba/fastjson/branch/master/graph/badge.svg)](https://codecov.io/gh/alibaba/fastjson/branch/master) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.alibaba/fastjson/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.alibaba/fastjson/) [![GitHub release](https://img.shields.io/github/release/alibaba/fastjson.svg)](https://github.com/alibaba/fastjson/releases) [![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) [![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready—​to—​Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/alibaba/fastjson) [![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/fastjson2.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:fastjson2).

kandi-support Support

  • fastjson has a highly active ecosystem.
  • It has 24265 star(s) with 6431 fork(s). There are 1340 watchers for this library.
  • There were 1 major release(s) in the last 6 months.
  • There are 1683 open issues and 1576 have been closed. On average issues are closed in 119 days. There are 136 open pull requests and 0 closed requests.
  • It has a positive sentiment in the developer community.
  • The latest version of fastjson is 1.2.79

quality kandi Quality

  • fastjson has 0 bugs and 0 code smells.

securitySecurity

  • fastjson has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • fastjson code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.

license License

  • fastjson is licensed under the Apache-2.0 License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.

buildReuse

  • fastjson releases are available to install and integrate.
  • Deployable package is available in Maven.
  • Build file is available. You can build the component from source.
  • Installation instructions are not available. Examples and code snippets are available.
  • fastjson saves you 177099 person hours of effort in developing the same functionality from scratch.
  • It has 181091 lines of code, 19450 functions and 3015 files.
  • It has low code complexity. Code complexity directly impacts maintainability of the code.
Top functions reviewed by kandi - BETA

kandi has reviewed fastjson and discovered the below as its top functions. This is intended to give you an instant insight into fastjson implemented functionality, and help decide if they suit your requirements.

  • Build JavaBeanInfo from given class .
  • Deserialize field information .
  • Scan a date in ISO8601 format .
  • Gets an object writer .
  • Write a string with double quotes .
  • Generate write as array .
  • tokenize object
  • Scan a field name .
  • Get the value of a property
  • Writes the value of the property .

fastjson Key Features

[Documentation Home](https://github.com/alibaba/fastjson/wiki)

[Contributing Code](https://github.com/nschaffner/fastjson/blob/master/CONTRIBUTING.md)

[Frequently Asked Questions](https://github.com/alibaba/fastjson/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98)

[maven][1]

[the latest JAR][2]

fastjson Examples and Code Snippets

  • default
  • SpringBoot: Validation without @Valid annotation
  • How to use lambda expression in android?
  • how to generate signed apk in android studio
  • How to don't serialize the class field in FastJson?
  • @JSONField it did not work in spring boot
  • Can't understand/find error in JSON config file referenced by Unity logs
  • Rails - How to add pagination to Fastjson api?
  • Error creating bean with name 'projectController': Unsatisfied dependency expressed through field 'service';
  • APM Go Agent isn't Sending Data to the APM Server
  • Getting NoSuchMethodError (DestinationAccessor) when launching Spring Boot project with generated Java VDM

default

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>1.2.76</version>
</dependency>

Community Discussions

Trending Discussions on fastjson
  • SpringBoot: Validation without @Valid annotation
  • How to use lambda expression in android?
  • how to generate signed apk in android studio
  • How to don't serialize the class field in FastJson?
  • @JSONField it did not work in spring boot
  • Error when starting spring-boot app. How to find out which dependency is causing AbstractMethodError
  • Can't understand/find error in JSON config file referenced by Unity logs
  • Rails - How to add pagination to Fastjson api?
  • java.lang.StackOverflowError happens when connect to Neo4j, in Springboot Mybatis
  • Error creating bean with name 'projectController': Unsatisfied dependency expressed through field 'service';
Trending Discussions on fastjson

QUESTION

SpringBoot: Validation without @Valid annotation

Asked 2021-Nov-23 at 04:53

I have a web socket handler inherited from AbstractWebSocketHandler that handles text messages. My DTOs use javax.validation.constraints for validation. So, in my REST endpoints, I simply can use the @Valid annotation to invoke the validator. However, as far as I know, this annotation is not usable in my web socket handler. How can I invoke the SpringBoot validator programmatically without this annotation?

Besides, is it possible to use the SpringBoot de-serializer for messages instead of JSON.parseObject?

Example:

import javax.validation.constraints.NotBlank;
import lombok.Data;

@Data
class CustomMessage {
    @NotBlank
    private String text;
}
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import lombok.NonNull;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.handler.AbstractWebSocketHandler;

@Component
@Slf4j
public class MyCustomWebSocketHandler extends AbstractWebSocketHandler {
    @Override
    protected void handleTextMessage(@NonNull WebSocketSession session, @NonNull TextMessage message) {
        CustomMessage customMessage = JSON.parseObject(message.getPayload(), CustomMessage.class);
        // Validate the message according to javax.validation annotations and throw MethodArgumentNotValidException if invalid
        log.debug("Received valid message {}", customMessage)
    }
}

ANSWER

Answered 2021-Nov-23 at 04:53

You will use a Validator to fill a list of ConstraintViolation. An example could looks like this :

public abstract class GenericService<T> {

    protected Validator validator;

    protected void validateDomainRecord(T object, String message) {
        Set<ConstraintViolation<T>> violations = validator.validate(object);
        if(!violations.isEmpty()) {
            throw new ConstraintViolationException(message, violations);
        }
    }
}

In your case, your code will looks something like this :

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import lombok.NonNull;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.handler.AbstractWebSocketHandler;

@Component
@Slf4j
public class MyCustomWebSocketHandler extends AbstractWebSocketHandler {

    private Validator validator;
    
    @Override
    protected void handleTextMessage(@NonNull WebSocketSession session, @NonNull TextMessage message) {
        CustomMessage customMessage = JSON.parseObject(message.getPayload(), CustomMessage.class);
        // Validate the message according to javax.validation annotations and throw MethodArgumentNotValidException if invalid
        ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
        validator = factory.getValidator();            
        Set<ConstraintViolation<CustomMessage>> violations = validator.validate(customMessage);
        if(!violations.isEmpty()) {
            throw new ConstraintViolationException(message, violations);
        }

        log.debug("Received valid message {}", customMessage)
    }
}

Take look a this good tutorial for more details. I guess it is also possible to customize your validation and your exception too.

Source https://stackoverflow.com/questions/70029336

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install fastjson

You can download it from GitHub, Maven.
You can use fastjson like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the fastjson component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .