Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException #722

Open
ljf88 opened this issue Jul 29, 2024 · 1 comment
Open

NullReferenceException #722

ljf88 opened this issue Jul 29, 2024 · 1 comment

Comments

@ljf88
Copy link

ljf88 commented Jul 29, 2024

Use Version:7.4.0

Source Class:
public class BaseResponse
{
   public string? TraceId { get; set; }
    public Guid InvoiceId { get; set; }
    public GatewayActionResultEnum ActionResult { get; set; }
    public string? ActionResultDescription { get; set; }
    public string? UniqueId { get; set; }
    public BaseRequest RawRequest { get; set; }
    public object RawResponse { get; set; }
    public dynamic? ResponseEntity { get; set; }
    public HttpStatusCode? StatusCode { get; set; }
    public List<Error> Errors { get; set; } = [];
    public bool IsRetry { get; set; }
}

public record Error(string Description, string? Code, string? Name);

public class PrepareResponse : BaseResponse
{
}

Target Class:
public class BaseRes
{
public Guid InvoiceId { get; set; }
public GatewayActionResultEnum ActionResult { get; set; }
public string? ActionResultDescription { get; set; }
public string? UniqueId { get; set; }
public object RawRequest { get; set; }
public string RawResponse { get; set; }
public dynamic? ResponseEntity { get; set; }
public bool IsFriendlyTip { get; set; } = false;
public string? FriendlyTip { get; set; }
public bool IsRetry { get; set; }
public string? TraceId { get; set; }
}

public class PrepareRes : BaseRes
{
    public Payment Payment { get; set; }
    public string? RedirectUrl { get; set; }
}

public partial class Payment
{
public Guid PaymentId { get; set; }
public string GatewayPayerId { get; set; } = null!;
public short? LastStatus { get; set; }
public DateTime CreateTime { get; set; }
public string GatewayPaymentId { get; set; } = null!;
public string Currency { get; set; } = null!;
public decimal Price { get; set; }
public string? Memo { get; set; }
public string GatewayPayerName { get; set; } = null!;
}

test data:
{"InvoiceId":"03f38e68-792a-48c0-a8ee-1d7877b2f7c9","ActionResult":1,"ActionResultDescription":null,"UniqueId":null,"RawRequest":null,"RawResponse":null,"ResponseEntity":null,"StatusCode":null,"Errors":[],"IsRetry":false,"TraceId":null}

call code:
source.Adapt(TypeAdapterConfig.GlobalSettings) ;
or
source.Adapt();

Error message:"Object reference not set to an instance of an object."
StackTrack:" 在 Mapster.TypeAdapter.Adapt[TDestination](Object source, TypeAdapterConfig config)"

description:
When deleting the TraceId attribute in the baseResponse class or changing the TraceId attribute in the source and target classes from string? to string, the conversion works fine.

@ljf88
Copy link
Author

ljf88 commented Jul 29, 2024

Supplementary Description:
If you change the type of TraceId to e.g. int?, long?, the conversion is also normal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant