flashport/json-marshaller 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

flashport/json-marshaller

最新稳定版本:v0.0.13

Composer 安装命令:

composer require flashport/json-marshaller

包简介

A simple JSON Marshaller/Unmarshaller library.

README 文档

README

This lib provides marshalling and unmarshalling functionality, allowing JSON strings to be cast into objects or vice versa.

Usage:

Object example:

class Person{

    // It supports custom property names
    #[JsonProperty("fullName")]
    public string $name;
    
    // It also supports validation attributes
    #[JsonValidateRequired]
    public string $email;
    
    // Equals can be a single value or an array
    #[JsonValidateEquals(["active", "inactive"])]
    public string $status;
    
    // It is necessary to define the array type
    #[JsonPropertyType(Address::class)]
    public array $addresses;
    
    // For array with scalar types
    #[JsonPropertyType(ScalarTypes::INTEGER)]
    public array $luckyNumbers;
    
    // The type can be inferred from the property, or from the attribute.
    // At least one is required
    public Address $billingAddress;
    
    #[JsonPropertyType(Address::class)]
    public $shippingAddress;
}

Marshalling:

$json = new \JsonMarshaller\JsonMarshaller();
$jsonString = $json->marshal($myObject);

Unmarshalling:

$json = new \JsonMarshaller\JsonMarshaller();
$person = $json->unmarshal($jsonString, Person::class)

统计信息

  • 总下载量: 1.05k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-10