当前位置: 首页 > news >正文

Jackson类层次结构中的一些应用(Inheritance with Jackson)

Have a look at working with class hierarchies in Jackson.
如何在Jackson中使用类层次结构。

Inclusion of Subtype Information

There are two ways to add type information when serializing and deserializing data objects, namely global default typing and per-class annotations.

Global Default Typing

@Data
@AllArgsConstructor
@NoArgsConstructor
public abstract class Vehicle {private String make;private String model;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Car extends Vehicle {private int seatingCapacity;private double topSpeed;public Car(String make, String model, int seatingCapacity, double topSpeed) {super(make, model);this.seatingCapacity = seatingCapacity;this.topSpeed = topSpeed;}
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Truck extends Vehicle {private double payloadCapacity;public Truck(String make, String model, double payloadCapacity) {super(make, model);this.payloadCapacity = payloadCapacity;}
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Fleet {private List<Vehicle> vehicles;
}
安全白名单
PolymorphicTypeValidator ptv = BasicPolymorphicTypeValidator.builder().allowIfSubType("javabasic.enumprac").allowIfSubType("java.util.ArrayList").build();ObjectMapper mapper = new ObjectMapper();
mapper.activateDefaultTyping(ptv, ObjectMapper.DefaultTyping.NON_FINAL);Car car = new Car("Mercedes-Benz", "S500", 5, 250.0);
Truck truck = new Truck("Isuzu", "NQR", 7500.0);
List<Vehicle> vehicles = new ArrayList<>();
vehicles.add(car);
vehicles.add(truck);
Fleet serializedFleet = new Fleet();
serializedFleet.setVehicles(vehicles);String jsonDataString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(serializedFleet);
System.out.println(jsonDataString);
[ "javabasic.enumprac.Fleet", {"vehicles" : [ "java.util.ArrayList", [ [ "javabasic.enumprac.Car", {"make" : "Mercedes-Benz","model" : "S500","seatingCapacity" : 5,"topSpeed" : 250.0} ], [ "javabasic.enumprac.Truck", {"make" : "Isuzu","model" : "NQR","payloadCapacity" : 7500.0} ] ] ]
} ]
String JSON= "[ \"javabasic.enumprac.Fleet\", {\n" +"  \"vehicles\" : [ \"java.util.ArrayList\", [ [ \"javabasic.enumprac.Car\", {\n" +"    \"make\" : \"Mercedes-Benz\",\n" +"    \"model\" : \"S500\",\n" +"    \"seatingCapacity\" : 5,\n" +"    \"topSpeed\" : 250.0\n" +"  } ], [ \"javabasic.enumprac.Truck\", {\n" +"    \"make\" : \"Isuzu\",\n" +"    \"model\" : \"NQR\",\n" +"    \"payloadCapacity\" : 7500.0\n" +"  } ] ] ]\n" +"} ]";Fleet deserializedFleet = mapper.readValue(JSON, Fleet.class);
System.out.println(deserializedFleet);
Fleet(vehicles=[Car(seatingCapacity=5, topSpeed=250.0), Truck(payloadCapacity=7500.0)])

Per-Class Annotations

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME,include = JsonTypeInfo.As.PROPERTY,property = "type")
@JsonSubTypes({@JsonSubTypes.Type(value = Car.class, name = "car"),@JsonSubTypes.Type(value = Truck.class, name = "truck")
})
@Data
@AllArgsConstructor
@NoArgsConstructor
public abstract class Vehicle {private String make;private String model;
}

其他model不变

Car car = new Car("Mercedes-Benz", "S500", 5, 250.0);
Truck truck = new Truck("Isuzu", "NQR", 7500.0);
List<Vehicle> vehicles = new ArrayList<>();
vehicles.add(car);
vehicles.add(truck);
Fleet serializedFleet = new Fleet();
serializedFleet.setVehicles(vehicles); 
ObjectMapper mapper = new ObjectMapper();
String jsonDataString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(serializedFleet);
System.out.println(jsonDataString);
{"vehicles" : [ {"type" : "car","make" : "Mercedes-Benz","model" : "S500","seatingCapacity" : 5,"topSpeed" : 250.0}, {"type" : "truck","make" : "Isuzu","model" : "NQR","payloadCapacity" : 7500.0} ]
}
Fleet deserializedFleet = mapper.readValue(jsonDataString, Fleet.class);
System.out.println(deserializedFleet);
Fleet(vehicles=[Car(seatingCapacity=5, topSpeed=250.0), Truck(payloadCapacity=7500.0)])

Ignoring Properties from a Supertype

Sometimes, some properties inherited from superclasses need to be ignored during serialization or deserialization. This can be achieved by one of three methods: annotations, mix-ins and annotation introspection.

Annotations

有两种常用的Jackson注释来忽略属性,它们是@JsonIgnore@JsonIgnoreProperties

@JsonIgnore directly applied to type members.
@JsonIgnoreProperties applied to type and type member.

@JsonIgnoreProperties is more powerful
it can ignore properties inherited from supertypes that we do not have control of.
it can ignore many properties at once.

@Data
@AllArgsConstructor
@NoArgsConstructor
public abstract class Vehicle {private String make;private String model;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties({ "model", "seatingCapacity" })
public class Car extends Vehicle {private int seatingCapacity;@JsonIgnoreprivate double topSpeed;public Car(String make, String model, int seatingCapacity, double topSpeed) {super(make, model);this.seatingCapacity = seatingCapacity;this.topSpeed = topSpeed;}
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Crossover extends Car {private double towingCapacity;public Crossover(String make, String model, int seatingCapacity, double topSpeed, double towingCapacity) {super(make, model, seatingCapacity, topSpeed);this.towingCapacity = towingCapacity;}
}
@Data
@AllArgsConstructor
public class Sedan extends Car {public Sedan(String make, String model, int seatingCapacity, double topSpeed) {super(make, model, seatingCapacity, topSpeed);}
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Fleet {private List<Vehicle> vehicles;
}
Sedan sedan = new Sedan("Mercedes-Benz", "S500", 5, 250.0);
Crossover crossover = new Crossover("BMW", "X6", 5, 250.0, 6000.0);
List<Vehicle> vehicles = new ArrayList<>();
vehicles.add(sedan);
vehicles.add(crossover);ObjectMapper mapper = new ObjectMapper();
String jsonDataString = mapper.writeValueAsString(vehicles);System.out.println(jsonDataString);
[{"make":"Mercedes-Benz"},{"make":"BMW","towingCapacity":6000.0}]

Mix-ins

Mix-ins allow us to ignoring properties when serializing and deserializing without the need to directly apply annotations to a class.
This is especially useful when dealing with third-party classes

@Data
@AllArgsConstructor
@NoArgsConstructor
public abstract class Vehicle {private String make;private String model;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Car extends Vehicle {private int seatingCapacity;private double topSpeed;public Car(String make, String model, int seatingCapacity, double topSpeed) {super(make, model);this.seatingCapacity = seatingCapacity;this.topSpeed = topSpeed;}
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Crossover extends Car {private double towingCapacity;public Crossover(String make, String model, int seatingCapacity, double topSpeed, double towingCapacity) {super(make, model, seatingCapacity, topSpeed);this.towingCapacity = towingCapacity;}
}
@Data
@AllArgsConstructor
public class Sedan extends Car {public Sedan(String make, String model, int seatingCapacity, double topSpeed) {super(make, model, seatingCapacity, topSpeed);}
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Fleet {private List<Vehicle> vehicles;
}
 public static void main(String[] args) throws JsonProcessingException {ObjectMapper mapper = new ObjectMapper();mapper.addMixIn(Car.class, CarMixIn.class);Sedan sedan = new Sedan("Mercedes-Benz", "S500", 5, 250.0);Crossover crossover = new Crossover("BMW", "X6", 5, 250.0, 6000.0);List<Vehicle> vehicles = new ArrayList<>();vehicles.add(sedan);vehicles.add(crossover);String jsonDataString = mapper.writeValueAsString(vehicles);System.out.println(jsonDataString);}private abstract class CarMixIn {@JsonIgnorepublic String make;@JsonIgnorepublic String topSpeed;}
原始值:
[{"make":"Mercedes-Benz","model":"S500","seatingCapacity":5,"topSpeed":250.0},{"make":"BMW","model":"X6","seatingCapacity":5,"topSpeed":250.0,"towingCapacity":6000.0}]ignore以后得值
[{"model":"S500","seatingCapacity":5},{"model":"X6","seatingCapacity":5,"towingCapacity":6000.0}]

Annotation Introspection

the most powerful method to ignore supertype properties since it allows for detailed customization using the AnnotationIntrospector.

class IgnoranceIntrospector extends JacksonAnnotationIntrospector {public boolean hasIgnoreMarker(AnnotatedMember m) {return m.getDeclaringClass() == Vehicle.class && m.getName() == "model"|| m.getDeclaringClass() == Car.class|| m.getName() == "towingCapacity"|| super.hasIgnoreMarker(m);}
}
Sedan sedan = new Sedan("Mercedes-Benz", "S500", 5, 250.0);
Crossover crossover = new Crossover("BMW", "X6", 5, 250.0, 6000.0);
List<Vehicle> vehicles = new ArrayList<>();
vehicles.add(sedan);
vehicles.add(crossover);ObjectMapper mapper = new ObjectMapper();
mapper.setAnnotationIntrospector(new IgnoranceIntrospector());
String jsonDataString = mapper.writeValueAsString(vehicles);
System.out.println(jsonDataString);
[{"make":"Mercedes-Benz"},{"make":"BMW"}]

Subtype Handling Scenarios

Conversion Between Subtypes

Jackson allows an object to be converted to aother type object.
it is most helpful when used between two subtypes of the same interface or class to secure values and functionality.

@Data
@AllArgsConstructor
@NoArgsConstructor
public abstract class Vehicle {private String make;private String model;
}

在Car和Truck的属性上添加@JsonIgnore注释以避免不兼容

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Car extends Vehicle {@JsonIgnoreprivate int seatingCapacity;@JsonIgnoreprivate double topSpeed;public Car(String make, String model, int seatingCapacity, double topSpeed) {super(make, model);this.seatingCapacity = seatingCapacity;this.topSpeed = topSpeed;}
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Truck extends Vehicle {@JsonIgnoreprivate double payloadCapacity;public Truck(String make, String model, double payloadCapacity) {super(make, model);this.payloadCapacity = payloadCapacity;}
}
Car car = new Car("Benz", "S500", 5, 250.0);
Truck truck1 = new Truck("Isuzu", "NQR", 7500.0);ObjectMapper mapper = new ObjectMapper();String s = mapper.writeValueAsString(car);
System.out.println(s);String s1 = mapper.writeValueAsString(truck1);
System.out.println(s1);Truck truck = mapper.convertValue(car, Truck.class);
System.out.println(truck);
{"make":"Benz","model":"S500"}
{"make":"Isuzu","model":"NQR"}
Truck(payloadCapacity=0.0)

Deserialization Without No-arg Constructors

默认情况下,Jackson通过使用无参数构造函数来重新创建数据对象。
By default, Jackson recreates data objects by using no-arg constructors.

In a class hierarchy where a no-arg constructor must be added to a class and all those higher in the inheritance chain. In these cases, creator methods come to the rescue.
Specifically, all no-arg constructors are dropped, and constructors of concrete subtypes are annotated with @JsonCreator and @JsonProperty to make them creator methods.

@Data
@AllArgsConstructor
@NoArgsConstructor
public abstract class Vehicle {private String make;private String model;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Car extends Vehicle {private int seatingCapacity;private double topSpeed;@JsonCreatorpublic Car(@JsonProperty("make") String make,@JsonProperty("model") String model,@JsonProperty("seating") int seatingCapacity,@JsonProperty("topSpeed") double topSpeed) {super(make, model);this.seatingCapacity = seatingCapacity;this.topSpeed = topSpeed;}
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Truck extends Vehicle {private double payloadCapacity;@JsonCreatorpublic Truck(@JsonProperty("make") String make,@JsonProperty("model") String model,@JsonProperty("payload") double payloadCapacity) {super(make, model);this.payloadCapacity = payloadCapacity;}
}
Car car = new Car("Mercedes-Benz", "S500", 5, 250.0);
Truck truck = new Truck("Isuzu", "NQR", 7500.0);
List<Vehicle> vehicles = new ArrayList<>();
vehicles.add(car);
vehicles.add(truck);
Fleet serializedFleet = new Fleet();
serializedFleet.setVehicles(vehicles);ObjectMapper mapper = new ObjectMapper();
mapper.enableDefaultTyping();
String jsonDataString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(serializedFleet);
System.out.println(jsonDataString);
Fleet fleet = mapper.readValue(jsonDataString, Fleet.class);
System.out.println(fleet);
{"vehicles" : [ "java.util.ArrayList", [ [ "javabasic.enumprac.prac.Car", {"make" : "Mercedes-Benz","model" : "S500","topSpeed" : 250.0,"seatingCapacity" : 5} ], [ "javabasic.enumprac.prac.Truck", {"make" : "Isuzu","model" : "NQR","payloadCapacity" : 7500.0} ] ] ]
}Fleet(vehicles=[Car(seatingCapacity=5, topSpeed=250.0), Truck(payloadCapacity=7500.0)])

-----------------------------------------------------------------------------读书笔记摘自 文章:Inheritance with Jackson

相关文章:

Jackson类层次结构中的一些应用(Inheritance with Jackson)

Have a look at working with class hierarchies in Jackson. 如何在Jackson中使用类层次结构。 Inclusion of Subtype Information There are two ways to add type information when serializing and deserializing data objects, namely global default typing and per-cl…...

Python求均值、方差、标准偏差SD、相对标准偏差RSD

均值 均值是统计学中最常用的统计量&#xff0c;用来表明资料中各观测值相对集中较多的中心位置。用于反映现象总体的一般水平&#xff0c;或分布的集中趋势。 import numpy as npa [2, 4, 6, 8]print(np.mean(a)) # 均值 print(np.average(a, weights[1, 2, 1, 1])) # 带…...

SQL ASNI where from group order 顺序

SQL语句执行顺序&#xff1a; from–>where–>group by -->having — >select --> order 第一步&#xff1a;from语句&#xff0c;选择要操作的表。 第二步&#xff1a;where语句&#xff0c;在from后的表中设置筛选条件&#xff0c;筛选出符合条件的记录。 …...

springboot(39) : RestTemplate完全体

HTTP请求调用集成,支持GET,POST,JSON,Header调用,日志打印,请求耗时计算,设置中文编码 1.使用(注入RestTemplateService) Autowiredprivate RestTemplateService restTemplateService; 2.RestTemplate配置类 import org.springframework.context.annotation.Bean; import org.…...

python中计算2的32次方减1,python怎么算2的3次方

大家好&#xff0c;给大家分享一下怎么样用python编写2的n次方,n由键盘输入&#xff0c;很多人还不知道这一点。下面详细解释一下。现在让我们来看看&#xff01; ---恢复内容开始--- 1、内置函数&#xff1a;取绝对值函数abs() 2、内置函数&#xff1a;取最大值max()&#xff…...

阿里云SLB负载均衡ALB、CLB和NLB有什么区别?

阿里云负载均衡SLB分为传统型负载均衡CLB&#xff08;原SLB&#xff09;、应用型负载均衡ALB和网络型负载均衡NLB&#xff0c;三者有什么区别&#xff1f;CLB是之前的传统的SLB&#xff0c;基于物理机架构的4层负载均衡&#xff1b;ALB是应用型负载均衡&#xff0c;7层负载均衡…...

SynergyNet(头部姿态估计 Head Pose Estimation)复现 demo测试

目录 0 相关资料1 环境搭建2 安装 SynergyNet3 下载相关文件4 编译5 测试 0 相关资料 SynergyNet&#xff08;github&#xff09;&#xff1a;https://github.com/choyingw/SynergyNet 1 环境搭建 我用的AutoDL平台搭建 选择镜像 PyTorch 1.9.0 Python 3.8(ubuntu18.04) Cu…...

mysql高级(尚硅谷-夏磊)

目录 内容介绍 Linux下MySQL的安装与使用 Mysql逻辑架构 Mysql存储引擎 Sql预热 索引简介 内容介绍 1、Linux下MySQL的安装与使用 2、逻辑架构 3、sql预热 Linux下MySQL的安装与使用 1、docker安装docker run -d \-p 3309:3306 \-v /atguigu/mysql/mysql8/conf:/etc/my…...

C++实用技术(二)std::function和bind绑定器

目录 简介std::functionstd::function对象包装器std::function做回调函数 std::bind绑定器bind绑定普通函数bind绑定成员函数 简介 C11新增了std::function和std::bind。用于函数的包装以及参数的绑定。可以替代一些函数指针&#xff0c;回调函数的场景。 std::function std…...

vue框架 element导航菜单el-submenu 简单使用方法--以侧边栏举例

1、目标 实现动态增删菜单栏的效果&#xff0c;所以要在数据库中建表 2 、建表 2.1、表样式 2.2、表数据 3、实体类 import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor;import java.util.List;Data AllArgsConstructor NoArgsConstr…...

Nodejs 第八章(npm搭建私服)

构建npm私服 构建私服有什么收益吗&#xff1f; 可以离线使用&#xff0c;你可以将npm私服部署到内网集群&#xff0c;这样离线也可以访问私有的包。提高包的安全性&#xff0c;使用私有的npm仓库可以更好的管理你的包&#xff0c;避免在使用公共的npm包的时候出现漏洞。提高…...

React Native获取手机屏幕宽高(Dimensions)

import { Dimensions } from react-nativeconsole.log(Dimensions, Dimensions.get(window)) 参考链接&#xff1a; https://www.reactnative.cn/docs/next/dimensions#%E6%96%B9%E6%B3%95 https://chat.xutongbao.top/...

kubernetes基于helm部署gitlab

kubernetes基于helm部署gitlab 这篇博文介绍如何在 Kubernetes 中使用helm部署 GitLab。 先决条件 已运行的 Kubernetes 集群负载均衡器&#xff0c;为ingress-nginx控制器提供EXTERNAL-IP&#xff0c;本示例使用metallb默认存储类&#xff0c;为gitlab pods提供持久化存储&…...

jmeter 5.1彻底解决中文上传乱码

1.修改源码,然后重新打jar包,就是所有上传文件名重新获取文件名 参考链接:多种Jmeter中文乱码问题处理方法 - 51Testing软件测试网 2.修改Advanced,必须选java...

云运维工具

企业通常寻找具有成本效益的方法来优化创收&#xff0c;维护物理基础架构以托管服务器和应用程序以提供服务交付需要巨大的空间和前期资金&#xff0c;最重要的是&#xff0c;物理基础设施会产生额外的运营支出以进行定期维护&#xff0c;这对收入造成了沉重的损失。 云使企业…...

【RL】Wasserstein距离-GAN背后的直觉

一、说明 在本文中&#xff0c;我们将阅读有关Wasserstein GANs的信息。具体来说&#xff0c;我们将关注以下内容&#xff1a;i&#xff09;什么是瓦瑟斯坦距离&#xff1f;&#xff0c;ii&#xff09;为什么要使用它&#xff1f;iii&#xff09; 我们如何使用它来训练 GAN&…...

sentinel引入CommonFilter类

最近在做一个springcloudAlibaba项目&#xff0c;做链路流控模式时需要将入口资源关闭聚合&#xff0c;做法如下&#xff1a; spring-cloud-alibaba v2.1.1.RELEASE及前&#xff0c;sentinel1.7.0及后&#xff1a; 1.pom 中引入&#xff1a; <dependency><groupId>…...

Phoenix创建local index失败

执行创建local index出现如下错误 0: jdbc:phoenix:hbase01:2181> create local index local_index_name on "test" ("user"."name","user"."address"); 23/07/28 17:28:56 WARN client.SyncCoprocessorRpcChannel: Cal…...

css3 hover border 流动效果

/* Hover 边线流动 */.hoverDrawLine {border: 0 !important;position: relative;border-radius: 5px;--border-color: #60daaa; } .hoverDrawLine::before, .hoverDrawLine::after {box-sizing: border-box;content: ;position: absolute;border: 2px solid transparent;borde…...

jdk安装

JDK的下载、安装和环境配置教程&#xff08;2021年&#xff0c;win10&#xff09;_「已注销」的博客-CSDN博客_jdk 以上文章如果没有成功在环境变量中part再添加一句 C:\Program Files (x86)\Java\jdk1.7.0_80\bin 安装目录下的bin目录 写完环境后重启 &#x1f4ce;jdk-20_w…...

用快马平台实践vibe coding:5分钟构建你的音乐可视化应用原型

最近在探索一种叫"vibe coding"的编程方式&#xff0c;简单来说就是跟着感觉走&#xff0c;先抓住创意灵感再考虑具体实现。正好发现InsCode(快马)平台特别适合这种创作方式&#xff0c;今天就带大家用5分钟做个音乐可视化应用&#xff0c;完全不需要从零开始写代码。…...

百考通:AI精准驱动数据分析,让数据价值更具人工写作的温度与逻辑

在数字化浪潮席卷各行各业的今天&#xff0c;数据已成为核心生产要素&#xff0c;但如何从海量数据中挖掘价值、辅助决策&#xff0c;始终是企业与个人面临的核心难题。传统数据分析流程繁琐、技术门槛高、周期漫长&#xff0c;让许多非专业人士望而却步。百考通&#xff08;ht…...

终极TypeScript设计模式指南:如何避免过度设计与模式滥用

终极TypeScript设计模式指南&#xff1a;如何避免过度设计与模式滥用 【免费下载链接】design_patterns_in_typescript :triangular_ruler: Design pattern implementations in TypeScript 项目地址: https://gitcode.com/gh_mirrors/de/design_patterns_in_typescript …...

Text-Grab:重新定义本地化OCR工具的高效办公体验

Text-Grab&#xff1a;重新定义本地化OCR工具的高效办公体验 【免费下载链接】Text-Grab Use OCR in Windows quickly and easily with Text Grab. With optional background process and notifications. 项目地址: https://gitcode.com/gh_mirrors/te/Text-Grab 在数字…...

LFM2.5-1.2B-Thinking-GGUF压力测试与性能调优:寻找最佳并发参数

LFM2.5-1.2B-Thinking-GGUF压力测试与性能调优&#xff1a;寻找最佳并发参数 1. 为什么需要压力测试 当你把LFM2.5-1.2B-Thinking-GGUF模型部署上线后&#xff0c;最担心的问题可能就是&#xff1a;这个服务能承受多少用户同时访问&#xff1f;会不会在高并发时崩溃&#xff…...

Cosmos-Reason1-7B保姆级教程:WebUI响应延迟优化(FlashAttention-2启用指南)

Cosmos-Reason1-7B保姆级教程&#xff1a;WebUI响应延迟优化&#xff08;FlashAttention-2启用指南&#xff09; 1. 引言 如果你已经用上了NVIDIA开源的Cosmos-Reason1-7B模型&#xff0c;体验过它强大的物理推理和视觉理解能力&#xff0c;那你可能也遇到了一个“甜蜜的烦恼…...

NXOpen 遍历部件并对每个部件加属性

NXOpen 遍历部件并对每个部件加属性 // Mandatory UF Includes #include <uf.h> #include <uf_object_types.h> // Internal Includes #include <NXOpen/ListingWindow.hxx> #include <NXOpen/NXMessageBox.hxx> #include <NXOpen/UI.hxx> //…...

万象视界灵坛应用场景:智能安防视频截图分析——自动识别‘是否含未授权人员/危险物品/异常行为’语义

万象视界灵坛在智能安防中的应用&#xff1a;自动识别异常语义分析 1. 智能安防的痛点与解决方案 传统安防监控系统面临三大核心挑战&#xff1a; 人力成本高&#xff1a;需要专人24小时盯守监控画面反应滞后&#xff1a;异常事件往往事后才发现漏检率高&#xff1a;人工监控…...

OpenClaw成本控制:Qwen2.5-VL-7B图文任务Token消耗优化

OpenClaw成本控制&#xff1a;Qwen2.5-VL-7B图文任务Token消耗优化 1. 多模态任务Token消耗的痛点 当我第一次用OpenClaw对接Qwen2.5-VL-7B模型处理图文混合任务时&#xff0c;账单上的Token消耗数字让我倒吸一口凉气。一个简单的"分析截图内容并生成报告"的任务&a…...

Spring_couplet_generation 模型推理性能优化:操作系统级调优指南

Spring_couplet_generation 模型推理性能优化&#xff1a;操作系统级调优指南 想让你的春联生成模型跑得更快、更稳吗&#xff1f;很多朋友在部署AI模型时&#xff0c;往往只关注模型本身和代码&#xff0c;却忽略了承载这一切的“地基”——操作系统。今天&#xff0c;我们就…...