我有一个看起来像这样的JSON:
{
"key1":[
{
"desc":"key1decs.",
"duration":50;
},{
"desc":"",
"duration":90;
},{
"desc":"Kurz vor...",
"duration":30;
}
],
"key2":[
{
"desc":"key2decs.",
"duration":50;
},{
"desc":"blabla",
"duration":90;
}
]
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试进行映射.但是我因为不同的未知/任意键而卡住了.我试过没有KVC的映射,但似乎没有工作.给我错误:keyPath'key1.desc'的值转换失败.没有从'__NSArrayI'转换为'NSString'的策略.等等每个属性.我在网上看到没有KVC的映射不支持数组作为内部结构.Plz,帮忙.什么是正确的方法?
编辑:ENtity:
@interface Sendung : NSObject
@property (nonatomic, strong) NSString *description;
@property (nonatomic, strong) NSNumber *duration;
@property (nonatomic, strong) NSNumber *sendungkey;
@end;
Run Code Online (Sandbox Code Playgroud)
控制器:
RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[Sendung class]];
mapping.forceCollectionMapping = YES;
[mapping mapKeyOfNestedDictionaryToAttribute:@"sendungkey"];
[mapping mapKeyPath:@"(sendungkey).desc" toAttribute:@"description"];
[mapping mapKeyPath:@"(sendungkey).duration" toAttribute:@"duration"];
[[RKObjectManager sharedManager].mappingProvider addObjectMapping:mapping ];
mapping = [[RKObjectManager sharedManager].mappingProvider objectMappingForClass:[Sendung class] ];
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:url objectMapping:mapping …Run Code Online (Sandbox Code Playgroud) 我使用MapStruct库来映射对象,但是我收到了这个错误:
无法将属性"java.util.Date aDate"映射到"javax.xml.bind.JAXBElement ADATE".考虑声明/实现映射方法:"javax.xml.bind.JAXBElement map(java.util.Date value)".
我的问题:我应该在哪里取消这种映射方法?
如果@Mapping/source 中引用的所有属性都为null,我希望生成的mapstruct 映射方法返回null。例如,我有以下映射:
@Mappings({
@Mapping(target = "id", source = "tagRecord.tagId"),
@Mapping(target = "label", source = "tagRecord.tagLabel")
})
Tag mapToBean(TagRecord tagRecord);
Run Code Online (Sandbox Code Playgroud)
生成的方法是:
public Tag mapToBean(TagRecord tagRecord) {
if ( tagRecord == null ) {
return null;
}
Tag tag_ = new Tag();
if ( tagRecord.getTagId() != null ) {
tag_.setId( tagRecord.getTagId() );
}
if ( tagRecord.getTagLabel() != null ) {
tag_.setLabel( tagRecord.getTagLabel() );
}
return tag_;
}
Run Code Online (Sandbox Code Playgroud)
测试用例:TagRecord 对象不为空,但具有 tagId==null 和 tagLibelle==null。
当前行为:返回的 Tag 对象不为 null,但具有 tagId==null 和 tagLibelle==null
如果(tagRecord.getTagId() == …
我是使用 MapStruct 的新手,因此面临一些相同的问题。
我有以下模型类:-
@Data
class User {
@Field
private String fullName;
@Field("experience")
private List<Experience> workExperience;
//other fields
}
@Data
class Experience {
private Date joiningDate;
//other fields
}
Run Code Online (Sandbox Code Playgroud)
现在,我有以下 DTO
@Data
class UserDTO {
private String firstName;
private String lastName;
private List<ExperienceDTO> workExperience;
//other fields
}
@Data
class ExperienceDTO {
private String joiningDate;
//other fields
}
Run Code Online (Sandbox Code Playgroud)
将 UserMapper 接口编写为:-
@Mapper(componentModel = "spring")
public interface UserMapper {
@Mappings({
@Mapping(target = "firstName",source = "fullName",
qualifiedByName = "firstNameExtractor"),
@Mapping(target = "lastName",source = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 MapStruct 将以下源类映射到目标类。
目标班级:
public class Response {
private List<Customer> customer = new ArrayList<Customer>();
}
public class Customer {
private String customerId;
private List<Product> products = new ArrayList<Product>();
}
public class CustProduct {
private String CustProductId;
private String CustPdtName;
private List<productDetail> CustProductDetails = new ArrayList<productDetail>();
}
Run Code Online (Sandbox Code Playgroud)
源类:
public class UserList {
protected List<User> user;
}
public class User {
protected String userId;
protected List<String> productRefId; //List of products for that particular user
}
public class ProductList {
protected List<Product> product; …Run Code Online (Sandbox Code Playgroud) java nested-lists object-object-mapping spring-boot mapstruct
我是ios/RESTKIT的新手.我正在尝试使用RESTKIT从ios设备上使用web服务.json回归可能有两种可能的结果.
A)在失败时,json结果如下所示(结果是字符串"null".错误代码可用):
{
status: false,
result: null
error: NO_SUCH_USER
}
Run Code Online (Sandbox Code Playgroud)
(A)的映射
RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[WsReturn class]];
[mapping mapKeyPath:@"result" toAttribute:@"result"];
[mapping mapKeyPath:@"status" toAttribute:@"status"];
[mapping mapKeyPath:@"error" toAttribute:@"error"];
[objectManager.mappingProvider setMapping:mapping forKeyPath:@"/"];
Run Code Online (Sandbox Code Playgroud)
B)在成功时,它看起来像(结果是一个"复杂的对象".错误代码为空):
{
status: true,
result: {
name: "Some User",
tasks: [
{
name: "Some Task1",
taskId: 10
},
{
name: "Some Task2",
taskId: 20
}
]
},
error: null
}
Run Code Online (Sandbox Code Playgroud)
(B)的映射
RKObjectMapping* taskMapping = [RKObjectMapping mappingForClass:[Task class]];
[taskMapping mapKeyPath:@"name" toAttribute:@"name"];
[taskMapping mapKeyPath:@"taskId" toAttribute:@"taskId"];
[objectManager.mappingProvider setMapping:taskMapping …Run Code Online (Sandbox Code Playgroud) 我不明白为什么在面向对象的开发中人们使用一些 ObjectMapper 类。你能解释一下这种课程的目的是什么吗?我也在寻找有关它的文档。我发现了很多解释如何创建它的信息,但没有关于如何以及为什么使用它。你知道我在哪里可以找到一篇好文章,关于这个的博客(如果可能的话,用 C#)。
一定要理解的子问题。C++ 中使用了 ObjectMapper 吗?
谢谢你。
<form class="form-horizontal" role="form" name="addCreditoBuscar" id="addCreditoBuscar" ng-controller="AddCreditoAppController">
<div class="form-group">
<label class="col-sm-2 col-sm-2 control-label">Buscar</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="buscar" ng-model="addCreditoBuscar.buscar" ng-required="true" placeholder="Buscar por cedula, nombre o apellido">
<span class="help-block" ng-show="addCreditoBuscar.buscar.$error.required">Este campo es requerido es requerido.</span>
</div>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
这是我的输入文本代码,但结果是这个 - http://prntscr.com/73otmc
input object object-object-mapping angularjs angularjs-ng-model
我正在尝试将cqlengine CQL 3 对象映射器与在 CherryPy 上运行的 Web 应用程序挂钩。尽管文档对查询非常清楚,但我仍然不知道如何对 cassandra 数据库中的现有表(和现有键空间)进行查询。例如,我已经有了包含标题、评级、年份字段的电影表。我想进行 CQL 查询
SELECT * FROM Movies
Run Code Online (Sandbox Code Playgroud)
建立连接后如何继续查询
from cqlengine import connection
connection.setup(['127.0.0.1:9160'])
Run Code Online (Sandbox Code Playgroud)
在KEYSPACE被称为“TEST1”。
java ×4
mapstruct ×4
restkit ×2
angularjs ×1
architecture ×1
c# ×1
cassandra ×1
cql ×1
cql3 ×1
cqlengine ×1
input ×1
ios ×1
iphone ×1
mapping ×1
nested-lists ×1
object ×1
objective-c ×1
spring ×1
spring-boot ×1